Link to home
Start Free TrialLog in
Avatar of Kongta
KongtaFlag for Switzerland

asked on

Top 10 & Last 5

I would like to show the Top10 & Last 5 of a table in one query. I tried

SELECT TOP 5 dbo_tblStatistikTmp_sb_Index.IQ, dbo_tblStatistikTmp_sb_Index.Index, dbo_tblStatistikTmp_sb_Index.Anzeige
FROM dbo_tblStatistikTmp_sb_Index
WHERE (((dbo_tblStatistikTmp_sb_Index.Technik_Anzahl)>50))
ORDER BY dbo_tblStatistikTmp_sb_Index.IQ;
 UNION
SELECT TOP 10 dbo_tblStatistikTmp_sb_Index.IQ, dbo_tblStatistikTmp_sb_Index.Index, dbo_tblStatistikTmp_sb_Index.Anzeige
FROM dbo_tblStatistikTmp_sb_Index
WHERE (((dbo_tblStatistikTmp_sb_Index.Technik_Anzahl)>50))
ORDER BY dbo_tblStatistikTmp_sb_Index.IQ DESC;

which gives me back the wrong results. Each query alone brings back the correct results, but in the UNION it doesn't work. Any idea why?
thx
Kongta
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kongta

ASKER

perfect, have many thanks for the prompt answer
rgds
Kongta
If that does not work, try saving the two parts of the UNION query seperately and writing your UNION query like this:

SELECT IQ,  Index, Anzeige
FROM qryTop5
UNION
SELECT IQ,  Index, Anzeige
FROM qryLast10

Open in new window

Glad that worked out :-)