14

I want to return all rows from biometrics, and grab extra data if the JOIN exists. However my current query only returns rows when the userid matches.

How may I fix this so it returns all biometric rows, and extra data from the JOIN if it exists?

SELECT b.id as id, g.date
FROM `biometrics` as b
INNER JOIN `users goals` as g ON biometricid = b.id and userid = $user->id
Nic
  • 11,374
  • 19
  • 75
  • 96
ditto
  • 5,429
  • 6
  • 48
  • 86

1 Answers1

21

Use a left outer join:

SELECT b.id as id, g.date
FROM `biometrics` as b
LEFT OUTER JOIN `users goals` as g ON biometricid = b.id and userid = $user->id

Nice examples of different join types can be found here.

Nic
  • 11,374
  • 19
  • 75
  • 96