This topic is locked

SQL SELECT - Present Values Side by Side from 1 table

11/25/2007 8:08:27 AM
PHPRunner General questions
A
acpan author

Hi,
i have been cracking my head over SQL left join and union

but can't get into the right palce.
I have a single table - TableA
Auto-Key Group Location Value

1 A Loc1 2.00

2 A Loc2 1.00

3 A Loc3 3.00

4 B Loc1 1.00

5 B Loc2 1.00

6 B Loc3 1.00
How to I make a join table like this:
Location Group_A_Value Group_B_Value

Loc1 2.00 1.00

Loc2 1.00 1.00

Loc3 3.00 1.00
Thanks

Dex

A
acpan author 11/25/2007

Found the solution as follows:
SELECT

t1.Group, t1.Location,

t1.Value as Group_A_Value,

t2.Value as Group_B_Value,

FROM

TableA as t1, TableA as t2

WHERE

(t1.Group = 'A' AND t2.Group = 'B')

AND

(t1.Location = t2.Location)
Hope it helps someone too.
Rgds

Dex