SQL select query problem

Posted on 2011-05-10
Last Modified: 2012-05-11
Hello EE,

Let'say i have 2 tables.

First table has:   ID, Description
Second has ID, (same id that table1)

in first table i have values:    1,2,3,4,5

how can I do a SELECT that if there is nothing in table 2  it returns  1,2,3,4,5  if lets say there is 1 and 3 it will return 1,2,4,5

lets say in table 2 there is 4,5  it would return 1,2,3

can y u help ?
Question by:PhilippeRenaud
    LVL 33

    Accepted Solution

    select *
    from Table1
    where ID not in (select distinct ID from Table2)
    LVL 32

    Expert Comment


    select ID, Description
    from table1
    left join table2 on =
    where is null
    LVL 1

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now