Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    6

    Unanswered: Outer Joins Help

    Hi,
    I am trying to write a query for the below problem:

    Table1:
    Columns: WFID, TaskID, DateStart, DateDone
    1,1,02/20/10,02/20/10
    1,2,02/21/10,02/21/10
    1,3,02/22/10,02/22/10
    2,1,02/10/10,02/10/10
    2,2,02/11/10,02/11/10
    2,3,02/12/10,02/12/10

    here wfid & taskid are the unique IDs

    Table2: ( this table stores comments only if it has for that WFID & TASKID)
    Columns: WFID,TASKID,Comments
    1,2,Some Comments on this task
    2,1,howdy

    I want to join these 2 tables (table1 & table2) in such a way that I get the below output:

    columns: WFID, TaskID, DateStart, DateDone, comments,
    1,1,02/20/10,02/20/10,NULL
    1,2,02/21/10,02/21/10,Some Comments on this task
    1,3,02/22/10,02/22/10,NULL
    2,1,02/10/10,02/10/10,howdy
    2,2,02/11/10,02/11/10,NULL
    2,3,02/12/10,02/12/10,NULL

    Thanks,
    Mahesh

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    this is a basic left outer join on two columns:
    Code:
    SELECT t1.WFID, t1.TaskID, t1.DateStart, t2.DateDone
      FROM Table1 AS t1
    LEFT OUTER
      JOIN Table2 AS t2
        ON t2.WFID = t1.WFID
       AND t2.TaskID = t1.TaskID
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2004
    Posts
    6
    oh great..thanks..I am new to SQL server

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    SQL Basics:
    SQL Tutorial
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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