Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    23

    Unanswered: please help me to optimize a SQL

    Hi,I have posted a same question,but i am not very cleay also.Please help me!
    Here are 2 table defined:
    points
    name points
    Wayne 168
    Jaromir 144
    Bobby 122

    pim
    name pim
    Mats 14
    Jaromir 18
    Bobby 12
    I define a SQL statement like this :
    SELECT points.name, points.points, pim.name, pim.pim FROM points FULL OUTER JOIN pim ON points.name=pim.name
    The result is:
    name name points pim
    Wayne NULL 168 NULL
    Jaromir Jaromir 144 18
    Bobby Bobby 122 12
    NULL Mats NULL 14

    Is there have someone help me to optimize that SQL ,let it return table like this :
    name points pim
    Wayne 168 NULL
    Jaromir 144 18
    Bobby 122 12
    Mats NULL 14
    Thanks !

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT coalesce(pim.name,points.name) as name
         , points.points
         , pim.pim 
      FROM points 
    FULL OUTER 
      JOIN pim 
        ON pim.name = points.name
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2007
    Posts
    23
    Thank you very much !

Posting Permissions

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