Unmatched records from Join

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Unmatched records from Join

    I have 2 tables.
    table1: ssn, name, date, status
    table2: ssn, name, dept
    I wanted to know if there is it possible to get all the
    unmatched records from either table. I want all the ssn's
    that do not have matches. Is that possible? I tried with
    an right/left outer join but it returns matches and
    unmatched. Thanks.


    Shawn Guest

  2. Similar Questions and Discussions

    1. Is left-join faster then inner join?
      Some people said that using left-join is generally faster than inner join, is that true? Thanks...
    2. JOIN vs no JOIN
      Is there any benefit in doing: SELECT a.f1, a.f2, b.f3 FROM t1 a INNER JOIN t2 b ON a.f1=b.id WHERE a.f1> 0 rather than SELECT a.f1, a.f2,...
    3. Is self-join appropriate?
      Please forgive me if this post is too long. I was trying to solve this (probably simple) issue for all day but I'm not as good in SQL as I thought...
    4. Querying for unmatched records in two tables
      I have two tables - One contains a list of all the zip codes in the US. The other table is basically a mailing list containing addresses of people...
    5. [Q] Self join portal records - why one too many?
      Using FMP 6.04 dev under MacOS X 10.2.6 I have a self-join working just fine with the desired records appearing in the portal but there is one...
  3. #2

    Default Re: Unmatched records from Join

    SELECT [ssn],[name],[date],[status] FROM [table1] WHERE [ssn] NOT IN (SELECT
    [ssn] FROM [table2])

    Ray at work

    "Shawn" <sfergus2@cscc.edu> wrote in message
    news:469301c37bbd$00552000$a601280a@phx.gbl...
    > I have 2 tables.
    > table1: ssn, name, date, status
    > table2: ssn, name, dept
    > I wanted to know if there is it possible to get all the
    > unmatched records from either table. I want all the ssn's
    > that do not have matches. Is that possible? I tried with
    > an right/left outer join but it returns matches and
    > unmatched. Thanks.
    >
    >

    Ray at Guest

  4. #3

    Default Re: Unmatched records from Join

    Shawn,

    A full outer join will do this for you. e.g. (SQL Server syntax):

    SELECT A.SSN AS SSN_1, B.SSN AS SSN_2
    FROM
    Table1 AS A
    FULL OUTER JOIN Table2 AS B
    ON A.SSN = B.SSN
    WHERE (A.SSN IS NULL) OR (B.SSN IS NULL)

    If your db platform does not support full outer joins, you'll need to UNION
    two separate outer joins. e.g. (Access syntax):

    SELECT A.SSN AS SSN_1, B.SSN AS SSN_2
    FROM
    Table1 AS A
    LEFT JOIN Table2 AS B
    ON A.SSN = B.SSN
    WHERE B.SSN IS NULL

    UNION

    SELECT B.SSN AS SSN_1, A.SSN AS SSN_2
    FROM
    Table2 AS A
    LEFT JOIN Table1 AS B
    ON A.SSN = B.SSN
    WHERE B.SSN IS NULL

    HTH,
    Nicole

    "Shawn" <sfergus2@cscc.edu> wrote in message
    news:469301c37bbd$00552000$a601280a@phx.gbl...
    > I have 2 tables.
    > table1: ssn, name, date, status
    > table2: ssn, name, dept
    > I wanted to know if there is it possible to get all the
    > unmatched records from either table. I want all the ssn's
    > that do not have matches. Is that possible? I tried with
    > an right/left outer join but it returns matches and
    > unmatched. Thanks.
    >
    >

    Nicole Calinoiu Guest

  5. #4

    Default Re: Unmatched records from Join

    Are u sure Its working
    Madhan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139