[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


SQL Filter Table by values in another table

Posted on 2012-09-20
Medium Priority
Last Modified: 2012-09-21
Hi there, I am trying to build a sql query where the results in table one do not equal the results in table two.  
Table1 Fields: ID
Table2 Fields: Item, String

String is filter by the parameter @string.

When the query executes I want Table1.ID to show all records except what table2 records shown by the filter.
I am very new to SQL syntax and am not sure how to join table1 and table2 to get the desired results.  Any help would be greatly appreciated!
Question by:trbaze
LVL 14

Assisted Solution

by:Máté Farkas
Máté Farkas earned 200 total points
ID: 38418664
What is the format of the filter in the Table2?

Author Comment

ID: 38418687
The filter is an nvarchar type string.  Is this what your asking?
LVL 21

Assisted Solution

by:Alpesh Patel
Alpesh Patel earned 200 total points
ID: 38421010
You need some column or key to map both tables Other then that you cannot join both tables.

Accepted Solution

Brainfeb earned 600 total points
ID: 38421755
select * from Table1 where id Not in ( select item from Table 2 where item = @String)

Author Closing Comment

ID: 38422256
Thanks to all for helping with this problem.  Brainfeb's answer gave me what I was looking for, however since my subquery has more than one result, I ended up creating a function to build my query.

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question