Reputation: 945
I have a table like below and i'm trying to select 1 series EID's i.e 1001,1002,1003,1004,1005 and 2 series EID's as seperate queries
EID PCNum
1001 8.6
1002 10
1003 9
1004 8
1005 7
2001 4
2002 1
2003 2
2004 3
2005 6
3001 8
3002 0
3003 7
3004 4
3005 4
And queries combined like below
EID PCNum EID PCNum EID PCNum
1001 8.6 2001 4 3001 8
1002 10 2002 1 3002 8
1003 9 2003 2 3003 8
1004 8 2004 3 3004 8
1005 7 2005 6 3005 8
How do i specify that in a sql query? Any suggestions? I tried UNION but giving some errors.
Upvotes: 0
Views: 32
Reputation: 316
Normally, you would have a column which would separate out EID from series, leaving you with just values like 001, 002, etc.
In this case you could JOIN
the data on itself +1000 times the series number. Something like this:
SELECT
t1.EID, t1.PCNum,
t2.EID, t2.PCNum,
t3.EID, t3.PCNum
FROM
table_name t1
INNER JOIN table_name t2 on t1.EID+1000 = t2.EID
INNER JOIN table_name t3 on t1.EID+2000 = t3.EID
WHERE t1.EID BETWEEN 1000 AND 1999
ORDER BY t1.EID
Upvotes: 1