Why is the following SQL query returning an error?
SELECT COUNT (DISTINCT rm.id)
FROM ts_room rm
LEFT JOIN ts_roomfacilities rf
ON rm.id = rf.room_id
LEFT JOIN ts_facilities f
ON f.id = rf.facilities_id
LEFT JOIN ts_building b
ON rm.building_id=b.id;
It seems logical at first glance!
Here is my SQLFiddle – http://sqlfiddle.com/#!2/a59fc/20
Don’t put a space between
COUNTand the first parenthesis. See it works now:http://sqlfiddle.com/#!2/a59fc/24
By the way, the error message you received at first tells you EXACTLY where your syntax error is.