Jump to content

Archived

This topic is now archived and is closed to further replies.

hitman6003

Join on multiple fields

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Try this:

 

SELECT *

FROM db

LEFT JOIN db2

ON db.field1 = db2.field1

AND db.field2 = db2.field2

 

 

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.