2 Top N queries joined (1 Viewer)

jazi

Registered User.
Local time
Today, 08:11
Joined
Mar 18, 2008
Messages
14
Col1 Col2

A 10 10
B 15 15
C 20 12
D 25 9
E 30 20
F 35 18
G 40 2
H 50 23
I 55 1
J 60 18

I have to get the Top 5 for each Col, grouped by group, but all in one table. What I did was split Col1 to one query with a return of 5. And also did that with Col2. But now I have to join them, and only a few records pop up, those which have the same group name, all others were excluded...what can I do?
 

boblarson

Smeghead
Local time
Today, 08:11
Joined
Jan 12, 2001
Messages
32,059
Col1 Col2

A 10 10
B 15 15
C 20 12
D 25 9
E 30 20
F 35 18
G 40 2
H 50 23
I 55 1
J 60 18

I have to get the Top 5 for each Col, grouped by group, but all in one table. What I did was split Col1 to one query with a return of 5. And also did that with Col2. But now I have to join them, and only a few records pop up, those which have the same group name, all others were excluded...what can I do?

You need two queries - one to get each column and then take those and turn them into a UNION query.
 

jazi

Registered User.
Local time
Today, 08:11
Joined
Mar 18, 2008
Messages
14
I figured but...

Maybe I am typing it wrong

Tried :

SELECT * FROM Query4
UNION ALL SELECT * FROM Query5;

However, I need 2 keep the col1 and col 2 seperate, I basically just need them to both be on one page, because I am making a graph that needs to use both values. Should I just be trying to do this in the query? Or will the Top 5 hinder that? I figured it wasn't possible that is why I am splittingthe queries than trying to join them after the query of top 5 is done.
 

Users who are viewing this thread

Top Bottom