Jump to content

Mysql_fetch_assoc and joins


Zeradin

Recommended Posts

Well, you really shouldn't have fields with the same names between tables unless they are foreign keys. But, if you do, then you should only SELECT the fields that you want. If there is still a duplicate between tables and you need both values then SELECT them using a name.

 

Selecting ONLY the fields you need

SELECT l.field1, l.field2,
       a.field3, a.field4
FROM leads l
JOIN accountants a ON l.to_id = a.id

 

Selecting fields with the same name in multiple tables

SELECT l.field1 as lead_field1, l.field2 as lead_field2,
       a.field1 as acct_field1, a.field2 as acct_field2
FROM leads l
JOIN accountants a ON l.to_id = a.id

Archived

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

×
×
  • Create New...

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.