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
  • 12,220
  • 20
  • 77
  • 105
ditto
  • 5,917
  • 10
  • 51
  • 88

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
  • 12,220
  • 20
  • 77
  • 105