I need to select from tblw few attributes based on few condition.
If the wid matches the id in tblMp and if the ind value is 'S' then i also need to select the id and desc from tbls along with the other attributes selected.
else if
wid matches with the id in tblmp but the value is 'o' then ihave to select the id and desc from the tblso table along with the attributes from tblw table.
else if
wid does not match with id in tblmp i have to select the id and desc from the tblso table along with the attributes in tblw table.
I have written the select something like this but am looking for a better way?Can this be done by using 'decode".
TblW tblMP tbls tblso
wid id f f
watt1 f id id
watt2 ind desc desc
watt3
watt4
...
...
...
watt20
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tbls.id,tbls.desc
from tblW,tblMP,tbls
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='S'
AND tblmp.f =tbls.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid(+)=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f
thanks.
raji96
If the wid matches the id in tblMp and if the ind value is 'S' then i also need to select the id and desc from tbls along with the other attributes selected.
else if
wid matches with the id in tblmp but the value is 'o' then ihave to select the id and desc from the tblso table along with the attributes from tblw table.
else if
wid does not match with id in tblmp i have to select the id and desc from the tblso table along with the attributes in tblw table.
I have written the select something like this but am looking for a better way?Can this be done by using 'decode".
TblW tblMP tbls tblso
wid id f f
watt1 f id id
watt2 ind desc desc
watt3
watt4
...
...
...
watt20
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tbls.id,tbls.desc
from tblW,tblMP,tbls
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='S'
AND tblmp.f =tbls.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid(+)=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f
thanks.
raji96