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
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
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?

 

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
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
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.

 

That worked... Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.