Jump to content

Left Join is Broken


unemployment

Recommended Posts

$compQ = "SELECT companies.companyid, companies.companyname, companies.companylogo, companies.companyoccupation, companies.industry, eQuestions.capitalrequested FROM companies LEFT JOIN eQuestions ON companies.companyid = eQuestions.companyid";

 

This is not displaying data correctly.  I'm assuming eQuestions.capitalrequested is not in the correct spot?

Link to comment
https://forums.phpfreaks.com/topic/223325-left-join-is-broken/
Share on other sites

What do you mean it's not displaying data correctly?  What's 'correctly' for you?  Each row for eQuestions will have a result row with its corresponding company based on its companyid = companies.companyid.  Also, any rows from companies not matched will have a result row with empty rows where results from eQuestions would be.

 

What are you trying to do?

 

Link to comment
https://forums.phpfreaks.com/topic/223325-left-join-is-broken/#findComment-1154486
Share on other sites

  Quote

What do you mean it's not displaying data correctly?  What's 'correctly' for you?  Each row for eQuestions will have a result row with its corresponding company based on its companyid = companies.companyid.  Also, any rows from companies not matched will have a result row with empty rows where results from eQuestions would be.

 

What are you trying to do?

 

I'm trying to make the query say only show companies where companyid matches in both companies and equestions.  Right now I am receiving all of the companies in my table before my actual company id. My actual company id is being shown last. 

 

I only want it to display data when the companyid's match in both tables.

Link to comment
https://forums.phpfreaks.com/topic/223325-left-join-is-broken/#findComment-1154488
Share on other sites

Raw, unchecked code:

SELECT companies.companyid, companies.companyname, companies.companylogo, companies.companyoccupation, companies.industry, eQuestions.capitalrequested FROM companies, eQuestions WHERE companies.companyid = eQuestions.companyid;

 

No Left Join needed.  You want Left Join when you require everything from the left table and also want what's matched on the right.

Link to comment
https://forums.phpfreaks.com/topic/223325-left-join-is-broken/#findComment-1154491
Share on other sites

  Quote

Raw, unchecked code:

SELECT companies.companyid, companies.companyname, companies.companylogo, companies.companyoccupation, companies.industry, eQuestions.capitalrequested FROM companies, eQuestions WHERE companies.companyid = eQuestions.companyid;

 

No Left Join needed.  You want Left Join when you require everything from the left table and also want what's matched on the right.

 

That worked... Thank you.

Link to comment
https://forums.phpfreaks.com/topic/223325-left-join-is-broken/#findComment-1154495
Share on other sites

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.