two tables x and y.
table x (id, a, b, c)
1, aval1, bval1, cval1
2, aval2, bval2, cval2
table y (xid, key, otherval)
1, ABC, y1
1, DEF, y2
1, GHI, y3
2, ABC, y4
2, GHI, y5
what i want -
x.id, x.a, x.b, x.c, ABC, DEF, GHI
1, aval1, bval1, cval1, y1, y2, y3
2, aval2, bval2, cval2, y4, -, y5
what i dont want to do -
select
x.id,
a,
b,
c,
ABC.otherval,
DEF.otherval,
GHI.otherval
from
x,
y ABC,
y DEF,
y GHI
where
x.id = ABC.xid
and x.id = DEF.xid
and x.id = GHI.xid
and ABC.key = 'ABC'
and DEF.key = 'DEF'
and GHI.key = 'GHI';
Is there another way ? I don't want to scan the same table 'y' thrice..