• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

SQL Filter Table by values in another table

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!
3 Solutions
Máté FarkasDatabase Developer and AdministratorCommented:
What is the format of the filter in the Table2?
trbazeAuthor Commented:
The filter is an nvarchar type string.  Is this what your asking?
Alpesh PatelAssistant ConsultantCommented:
You need some column or key to map both tables Other then that you cannot join both tables.
select * from Table1 where id Not in ( select item from Table 2 where item = @String)
trbazeAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now