title: Three tables join query not showing any data
body: <p>I have three tables users, favorites and friends.</p>
  <p>users : id, name, email</p>
  <p>favorites : id, favorite_id, user_id</p>
  <p>friends : id, friend_id, user_id</p>
  <p>Query 1 : Joining tables users and friends</p>
  <pre><code>select 
  friends.`friend_id`
  from users 
  left join friends on users.id = friends.`friend_id` 
  where users.id != 18 
  and (user_id = 18 or user_id is NULL) 
  order by id asc
  </code></pre>
  <p>Query 2: Joining tables users and favorites</p>
  <pre><code>select 
    users.`created_at`
  , users.name
  , users.email
  , users.`image`
  , users.is_online
  , favorites.`favorite_id`
  , users.id
  , user_id 
  from users 
  left join favorites on users.id = favorites.`favorite_id` 
  where users.id != 18 
  and (user_id = 18 or user_id is NULL) 
  order by id asc
  </code></pre>
  <p>Both the above queries are working fine,</p>
  <p>Now, what I want to do is join both the queries, I have tried something like this,</p>
  <p>Query Tried:</p>
  <pre><code>select 
    users.`created_at`
  , users.name
  , users.email
  , users.`image`
  , users.is_online
  , favorites.`favorite_id`
  , users.id
  , user_id
  , (
     select 
       friends.`friend_id` 
       from users 
       left join friends on users.id = friends.`friend_id` 
       where users.id != $user_id 
       and (user_id = $user_id or user_id is NULL)
     ) 
  from users 
  left join favorites on users.id = favorites.`favorite_id` 
  where users.id != $user_id 
  and (user_id = $user_id or user_id is NULL) 
  order by id asc
  </code></pre>
  <p>But, its showing no data,
  Where, I am missing. Please help me out.</p>
  <p>output from Query 1:</p>
  <pre><code>{
      &quot;data&quot;: [
          {
              &quot;friend_id&quot;: 2
          }
      ],
  </code></pre>
  <p>Output from query 2</p>
  <pre><code>&quot;data1&quot;: [
          {
              &quot;created_at&quot;: &quot;2020-08-04 23:53:53&quot;,
              &quot;name&quot;: &quot;yashyashwi&quot;,
              &quot;email&quot;: &quot;yashyashwi@gmail.com&quot;,
              &quot;image&quot;: &quot;1596540233.jpeg&quot;,
              &quot;is_online&quot;: 0,
              &quot;favorite_id&quot;: null,
              &quot;id&quot;: 1,
              &quot;user_id&quot;: null
          }
        ],
  </code></pre>
  <p>Desired output :</p>
  <pre><code> &quot;datas&quot;: [
              {
                  &quot;created_at&quot;: &quot;2020-08-04 23:53:53&quot;,
                  &quot;name&quot;: &quot;yashyashwi&quot;,
                  &quot;email&quot;: &quot;yashyashwi@gmail.com&quot;,
                  &quot;image&quot;: &quot;1596540233.jpeg&quot;,
                  &quot;is_online&quot;: 0,
                  &quot;favorite_id&quot;: null,
                  &quot;friend_id&quot;: 2,
                  &quot;id&quot;: 1,
                  &quot;user_id&quot;: null
              }
            ],
  </code></pre>