Jump to content

INNER JOIN query error


stubarny1

Recommended Posts

Hello,

 

I have the following sql query which works:

 

$query="SELECT * FROM submissions 
WHERE ((submission_employer_country = '$search_country') AND (submission_employer_department = '$search_department'))
order by submission_timestamp 
desc limit 10";

 

one of the variables returned is the user's account number. I then want to find the corresponding username for each account number, by querying the "accounts" tables as follows (I've replaced "*" from the code above with all the field names in the "submissions" table):

 

$query="SELECT submissions.submission_number, submissions.submission_employer_company, submissions.submission_employer_industry,
submissions.submission_employer_town_or_postcode, submissions.submission_employer_country, submissions.submission_employer_department,
submissions.submission_employer_department_hiring_situation_detailed, submissions.submission_employer_department_hiring_situation_summary,
submissions.submission_employer_application_contact, submissions.submission_employer_latitude,
submissions.submission_employer_longitude, submissions.submission_account_number, submissions.submission_timestamp,
accounts.account_number 
FROM submissions 
WHERE ((submission_employer_country = '$search_country') AND (submission_employer_department = '$search_department'))
INNER JOIN accounts 
ON submissions.submission_account_number=accounts.account_number
ORDER BY
submission_timestamp desc limit 10";

 

but the above code is failing. please could point me in the right direction?

Link to comment
Share on other sites

JOINS are part of the FROM clause, not the WHERE one.  Also - details of the "fail" are usualy warmly recieved.

$query="SELECT submissions.submission_number, submissions.submission_employer_company, submissions.submission_employer_industry,
submissions.submission_employer_town_or_postcode, submissions.submission_employer_country, submissions.submission_employer_department,
submissions.submission_employer_department_hiring_situation_detailed, submissions.submission_employer_department_hiring_situation_summary,
submissions.submission_employer_application_contact, submissions.submission_employer_latitude,
submissions.submission_employer_longitude, submissions.submission_account_number, submissions.submission_timestamp,
accounts.account_number 

FROM submissions INNER JOIN accounts 
ON (submissions.submission_account_number = accounts.account_number)

WHERE ((submission_employer_country = '$search_country') AND (submission_employer_department = '$search_department'))

ORDER BY
submission_timestamp desc limit 10";

 

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.