find record in 1 table not in another one without any primary key

  • hi

    i have 1 table like this

    table A

    Product_ID name desc

    123 abc new pencil

    234 def new pen

    345 efg new stage

    234 cde new black

    Table B

    Product_ID name desc

    123 abc new pencil

    234 def new pen

    567 efg new stage

    what i need to do is select all records from table A which is not in table B.

    if any of this column is not matching (Product_id,name,desc) this 3 r my primary key.

    how to do it with left join and null condition. do i need to give all 3 condition as OR ?

    if any of this 3 values r new it should ne new new record

    in this case this both should come as a result.

    345 efg new stage

    234 cde new black

    thanks

  • coool_sweet (11/9/2016)


    hi

    i have 1 table like this

    table A

    Product_ID name desc

    123 abc new pencil

    234 def new pen

    345 efg new stage

    234 cde new black

    Table B

    Product_ID name desc

    123 abc new pencil

    234 def new pen

    567 efg new stage

    what i need to do is select all records from table A which is not in table B.

    if any of this column is not matching (Product_id,name,desc) this 3 r my primary key.

    how to do it with left join and null condition. do i need to give all 3 condition as OR ?

    if any of this 3 values r new it should ne new new record

    in this case this both should come as a result.

    345 efg new stage

    234 cde new black

    thanks

    If all three columns are what makes up the criteria for a row to match then you would use AND not OR in your join predicates.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • maybe...

    SELECT *

    FROM Table_A

    EXCEPT

    SELECT *

    FROM Table_B

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • J Livingston SQL (11/9/2016)


    maybe...

    SELECT *

    FROM Table_A

    EXCEPT

    SELECT *

    FROM Table_B

    Further on J L's fine answer, use CTEs if the structures/data types do not match

    😎

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

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