need help with a sql query

  • I'm writing a sql query that pulls data from 2 tables based on a 3rd. the problem I'm having is that because of my where clause its only pulling the data that matches between the tables (not pulling blank entries like I'd like). This is what I currently have:

    select table1.column1, table2.column1, table2.column2

    from table1, table2, table3

    where table1.column2 = table3.column2 and table2.column3 = table3.column1

    this will return a results list with all entries in Table1.column1 that match the data in Table2 (as it should), I'd like to add the remainder of the data from table1.column1 that has no matches so I can cross compare and know which fields I'll need to enter data on. Can anyone point me in the right direction?

  • Firstly learn how to do ANSI joins. Then, to get the blank rows, use outer joins instead of inner joins;.

    SELECT table1.column1, table2.column1, table2.column2

    FROM table1

    LEFT OUTER JOIN table3 ON table1.column2 = table3.column2

    LEFT OUTER JOIN table2 ON table2.column3 = table3.column1

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gail!

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

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