Jump to content


Photo

Join on multiple fields


  • Please log in to reply
1 reply to this topic

#1 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 November 2005 - 08:03 PM

it's easiest if I just put up an example:

SELECT * FROM db
LEFT JOIN db2 ON db.field1 = db2.id

That works fine, but I have another field in "db" that I need to join to "db2".

I've tried:
SELECT * FROM db
LEFT JOIN db2 ON db.field1 = db2.id
LEFT JOIN db2 ON db.field2 = db2.id

And:
SELECT * FROM db
LEFT JOIN db2 ON db.field1 = db2.id, db.field2 = db2.id

And:

SELECT * FROM db
LEFT JOIN db2 ON db.field1, db.field2 = db2.id


But I get an error with each one.

Thanks for the help.

#2 sqlmc

sqlmc
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 23 November 2005 - 03:34 AM

Try this:

SELECT *
FROM db
LEFT JOIN db2
ON db.field1 = db2.field1
AND db.field2 = db2.field2






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users