I have tables contracts and users and i need to show contracts sorted by concatecated fields from users table. (and need outer join here because there is not always user present for contract)
SELECT *
FROM `contracts`
LEFT OUTER JOIN `users` ON `users`.id = `contracts`.account_manager_id
WHERE contracts.status != 'Archived'
ORDER BY CONCAT_WS(' ', IFNULL(`users.contact_first_name`, '')
, IFNULL(`users.contact_last_name`, ''))
LIMIT 0, 50
Problem: Unknown column users.contact_first_name
Remove the backticks here:
Change to:
Or if you really want to use backticks you can quote the table and column name separately: