Using the EXCEPT statement in MySql 5.1

I have a version of MySQL MySQL on my server. I am trying to execute this query:

SELECT File_Name
FROM Words_DB
WHERE Word_Name=" . $element . "
EXCEPT 
SELECT File_Name 
FROM Files_DB 
WHERE Display=0

I get an error message:

Error: you have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use next to "EXCEPT SELECT File_Name FROM Files_DB WHERE Display = 0" on line 4

Can someone tell me how I can fulfill this request in an alternative form?

Thanks Max.

+4
source share
2 answers

As far as I know, MySQL does not support the statement EXCEPT. Try instead:

SELECT File_Name
FROM Words_DB
WHERE Word_Name=" . $element . "
AND File_Name NOT IN (
  SELECT File_Name 
  FROM Files_DB 
  WHERE Display=0
)

NOT EXISTS, LEFT JOIN. MySQL , , .

+4
-2

All Articles