Select records not found in a table

  • Right now I have a 'clients' table that stores client information, and the primary key is clientID. For each client, we assess the risk of doing business with them. I have a 'risk' table that stores information about the risk assessment of each client. I need to find out which clients have not been risk-assessed, and I would like to know how I can do that. For example:

    'clients' table

    clientID    name

    1            ...

    2            ...

    3            ...

    4            ...

    'risk' table

    clientID    name

    2            ...

    4            ...

    results from query

    clientID    name

    1            ...

    3            ...

    I need a query that I can run and return the results as shown in results from query. Is this possible at all? Thanks in advance!

  • select * from clients left join risk on clients.id=risk.id

    where risk.id is null

  • and make sure you specify the outer table on the select list !!!!

    select clients.* from clients left join risk on clients.id=risk.id

    where risk.id is null

     


    * Noel

  • Thanks for the quick reply guys! I've got it down and it works beautifully. I appreicate it!

Viewing 4 posts - 1 through 3 (of 3 total)

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