Where to start?

  • I'm a little lost on where to start. I have two tables:

    Table11..........Table2

    Name.............ID1

    ID.................ID2

    ....................Link

    All I want to do is list all the names from Table1 where:

    Table1.ID <> Table2.ID1

    AND

    Table1.ID <> Table2.ID2

    Sounds easy, but I'm very new to SQL in general and can't get the results at all. Any help in the right direction would be great.

  • select t1.name

    from table1 t1

    where t1.id not in (select id1

    from table2

    union

    select id2 from table2)

    Might be able to make it run better or clean it up, but I think this is what you're asking.

  • That was what I needed. A few tweaks but it works great...thank you.

  • What were the "tweaks"?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • select name

    from table1 a

    where not exists(select 1 from table2 where id1=a.id and id2=a.id)

  • Since the title is "where to start" ...

    Start using aliasses everywhere to avoid confusion.

    (occurs especialy after query maintenance !)

    select name

    from table1 a

    where not exists(select 1 from table2 T2 where T2.id1=a.id and T2.id2=a.id)

    The query you've provided is not symanticaly the same as the one Steve provided !

    If you want the same result as Steve, you should use :

    where T2.id1=a.id OR T2.id2=a.id)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I just had some additions to the Where statemnt to filter certain items in the first database.

    Thanks Again

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply