Kongta
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_Ind ex.IQ, dbo_tblStatistikTmp_sb_Ind ex.Index, dbo_tblStatistikTmp_sb_Ind ex.Anzeige
FROM dbo_tblStatistikTmp_sb_Ind ex
WHERE (((dbo_tblStatistikTmp_sb_ Index.Tech nik_Anzahl )>50))
ORDER BY dbo_tblStatistikTmp_sb_Ind ex.IQ;
UNION
SELECT TOP 10 dbo_tblStatistikTmp_sb_Ind ex.IQ, dbo_tblStatistikTmp_sb_Ind ex.Index, dbo_tblStatistikTmp_sb_Ind ex.Anzeige
FROM dbo_tblStatistikTmp_sb_Ind ex
WHERE (((dbo_tblStatistikTmp_sb_ Index.Tech nik_Anzahl )>50))
ORDER BY dbo_tblStatistikTmp_sb_Ind ex.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
SELECT TOP 5 dbo_tblStatistikTmp_sb_Ind
FROM dbo_tblStatistikTmp_sb_Ind
WHERE (((dbo_tblStatistikTmp_sb_
ORDER BY dbo_tblStatistikTmp_sb_Ind
UNION
SELECT TOP 10 dbo_tblStatistikTmp_sb_Ind
FROM dbo_tblStatistikTmp_sb_Ind
WHERE (((dbo_tblStatistikTmp_sb_
ORDER BY dbo_tblStatistikTmp_sb_Ind
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Glad that worked out :-)
ASKER
rgds
Kongta