SQL Filter Table by values in another table

Posted on 2012-09-20
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 11

    Assisted Solution

    by:Máté Farkas
    What is the format of the filter in the Table2?
    LVL 3

    Author Comment

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

    Assisted Solution

    by:Alpesh Patel
    You need some column or key to map both tables Other then that you cannot join both tables.
    LVL 2

    Accepted Solution

    select * from Table1 where id Not in ( select item from Table 2 where item = @String)
    LVL 3

    Author Closing Comment

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

         When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now