Question : sql tuning

SELECT p.masterproviderid
              , rp.specialtyname
             , ps.specialtyid
           
FROM providermaster p, providerspecialty ps , provideraddress pa, rfproviderspecialty rp
WHERE p.MASTERPROVIDERID=1148421 and p.expireddate IS NULL
                                    AND   rp.specialtyid (+) = PS.SPECIALTYID
                                       AND   p.masterproviderid  = ps.masterproviderid (+)  
                                       AND pa.masterproviderid = p.masterproviderid



Am getting the result like this


MASTERPROVIDERID","SPECIALTYNAME",   "SPECIALTYID"
"1148421",          "Genetics"            "44"
"1148421",          "Genetics"            "44"
"1148421",          "Genetics"            "44"
"1148421",          "Genetics"            "44"
"1148421",  "Genetics - Clinical",        "45"
"1148421",  "Genetics - Clinical",        "45"
"1148421",  "Genetics - Clinical",        "45"
"1148421",  "Genetics - Clinical",        "45"
"1148421","Genetics - Clinical Molecular","47"
"1148421","Genetics - Clinical Molecular","47"


But I want the result
as

MASTERPROVIDERID","SPECIALTYNAME",   "SPECIALTYID"
"1148421",          "Genetics"            "44"
"1148421",  "Genetics - Clinical",        "45"
"1148421","Genetics - Clinical Molecular","47"

Please suggest how should I tweak this query

Answer : sql tuning

What version of Oracle are you using?

What you are wanting to do is PIVOT the data.  This is a little bit of a problem prior to 11gR2.

You can read about the various ways at:
http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
Random Solutions  
 
programming4us programming4us