Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reverse IN query 2

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
Table definition
tblFoo
x varchar

tblFoo
------
x
------
abc
def
ghi

I have a string like 'abc,def,ghi,jkl'
and I want to say return for me everything in
this string that is not in tblFoo. So basically
the reverse of:

SELECT *
FROM tblFOO
WHERE x NOT IN ('abc,def,ghi,jkl');


Ultimately I would be looking for the result to say jkl in this instance as it is in my string but not in tblFoo.

Thanks in advance for replies.

 
What you need to do is to have a function that would return your string, split by ',', as a table. You can also do it in-line in your SQL if you wish, but essentially it should be something like this:

If your string is 'abc, def, ghi, jkl', then your logic would form a table having abc, def, ghi, jkl as values. Let's call this temp_table with 'y' as a column.

After you have this table you can do:

select * from temp_table where y not in (select x from tblFoo)

 
an effective solution here is probably not ANSI SQL

you'd be better off re-posting this question in the forum for your particular database system

for example, in MySQL you can say

... WHERE FIND_IN_SET(x,'abc,def,ghi,jkl') = 0

but FIND_IN_SET works ~only~ in MySQL



r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
The gods are smiling, MySQL is the db vendor :)

Thanks for replies
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top