If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > please help me to optimize a SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-07, 09:41
yanqinghuang yanqinghuang is offline
Registered User
 
Join Date: Oct 2007
Posts: 23
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 !
Reply With Quote
  #2 (permalink)  
Old 11-05-07, 09:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
SELECT coalesce(pim.name,points.name) as name
     , points.points
     , pim.pim 
  FROM points 
FULL OUTER 
  JOIN pim 
    ON pim.name = points.name
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-05-07, 09:59
yanqinghuang yanqinghuang is offline
Registered User
 
Join Date: Oct 2007
Posts: 23
Thank you very much !
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On