I’m trying to query my database for unused listId’s but can’t quite seem to get the query syntax correct. Here is what I’ve tried:
SELECT DISTINCT pkListId FROM tblList
INNER JOIN InUseLists ON
tblList.pkListId NOT LIKE InUseLists.fkListId
Where tblList holds all List data, and InUseLists is a view holding all distinct listId’s from my relational table.
Currently my tblList holds listId 1-9
my relational table has fkListId 1,8,9 (used more than once)
So my view gets distinct values from the relational table – 1,8,9.
What is wrong with my query syntax?
It sounds like you want a
left join(which can succeed whether or not it finds a match in the “right” table), and then to select those rows where the join, in fact, failed to work.Something like:
(If
LIKEis the right operator here. Most joins use a simple equality check)If this still isn’t right, it might be better if you edited your question to include the sample data and expected results in a tabular form. At the moment, I’m still not sure what the contents of your tables are, and what you’re aiming for.