2 left joins on same column?

I need to left join different tables on one table column!

LEFT JOIN table1 u ON (u.id=g.entityid)
LEFT JOIN table2 s on (s.userid=u.id)

How to join them on u.id

If I do this it doesn’t return correct data!

Then your data probably isn’t what you think it is.

That left join syntax will only work if BOTH table1 and table2 have that value. You’d be better off joining table2 same field on the base table

SELECT g.field1
     , g.field2
     , s.field1
     , u.field1
  FROM table0 g
  LEFT JOIN table1 u ON g.entityid = u.id
  LEFT JOIN table2 s ON g.entityid = s.userid

Thanks but I don’t know why it’s messed up!

We don’t know for sure :wink:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.