Page 1 of 1

Help with MySQL table job

Posted: Mon Dec 08, 2008 12:32 am
by Mr Tech
First of all here is my MySQL. I've cut it down a little bit for easy reading:

Code: Select all

SELECT * FROM leads_tasks AS t 
JOIN leads AS l ON t.lead_id = l.id 
JOIN proposals_sent AS p ON t.database_id = p.proposal_id 
WHERE ....
Basically I need to join the first two tables: leads_tasks and leads. The third table (proposals_sent) is optional dependent on if there is any data from it. I only want to join it if there is anything that matches the t.database_id to p.proposal_id. If not, I just want it to join the first two tables and pull results from them.

However, with my current code, if there is nothing in the proposals_sent table, it says there are no rows.

I think I have to use LEFT JOIN or something like that but I'm not sure. Any help would be appreciated :)

Re: Help with MySQL table job

Posted: Mon Dec 08, 2008 5:22 am
by VladSun
Mr Tech wrote:I think I have to use LEFT JOIN or something like that but I'm not sure. Any help would be appreciated :)
Yes, you are right - use LEFT JOIN for proposals_sent table.

//offtopic
:twisted: :twisted: :twisted:
Avatars war !!!