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
https://forums.phpfreaks.com/topic/242462-inner-join-query-error/
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";

 

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.