Reputation: 1168
I have 2 tables, one with functions and one with used functions. I have a query which only has to show me the values which are not used. So it has to compare if the function name exists in the other table, if not show that value.
For example this is my database table functions:
function_id | function_name | function_description
1 | function_1 | lorem ipsum
2 | function_2 | dolor sit amet
And this is my table used functions:
register_id | function_activation | function_deactivation | etc
1 | function_1 | function_1 | lorem ipsum
So like function_2 does not exist in the used functions table. I used this query to check it:
SELECT * FROM functions WHERE NOT EXISTS
(SELECT function_activation, function_deactivation FROM used_functions)
But it shows me nothing. Am I using a wrong query or maybe something else?
Upvotes: 0
Views: 37
Reputation: 16573
You can do a LEFT JOIN
instead of a subquery.
SELECT functions.* FROM functions LEFT JOIN used_functions
ON functions.function_name = used_functions.function_activation
WHERE used_functions.function_activation IS NULL
Upvotes: 1
Reputation: 10665
try like this:
SELECT * FROM functions WHERE function_name NOT IN
(SELECT function_activation FROM used_functions)
Upvotes: 2