I have a legacy MySQL database (3.x) and I´m trying to run a query that returns all rows from a specific column where the values of the returned rows shall NOT exist in another column, from another table.
I´ve searched all similar questions here and googled for a solution, but could not find why I´m failing in executing this query.
The column from the first table (Table programs) is named 'fkfileid', and the column from the table I want to check against (Table imports) is named 'ifkfileid'. My query is supposed to return all rows from 'programs.fkfileid' that don´t have a matching value in 'imports.ifkfileid'.
This is the query:
SELECT fkfileid FROM programs WHERE fkfileid NOT IN (SELECT ifkfileid FROM imports)
I have to use 'NOT IN' instead of 'NOT EXISTS' because it´s a legacy MySQl database. The error I get from the database is the following:
"You have an error in your SQL syntax near 'SELECT ifkfileid FROM imports)' at line 1"
My query is very similar to several examples shown here, in similar posts. I don´t know where I´m doing wrong.
Example: SQL - find records from one table which don't exist in another
Also, I cannot use 'JOIN' statements because this query will be added to a much more complex query where I would not know how to make it work with 'JOIN'.
It´s not my intention to ask an stupid question with little effort, but I´m not being able to figure this one out...
Thanks for any help or insight,