Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Reverse IN query

Reverse IN query

Reverse IN query

Table definition
x varchar


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:

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.


RE: Reverse IN query

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)


RE: Reverse IN query

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

RE: Reverse IN query

The gods are smiling, MySQL is the db vendor :)

Thanks for replies

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close