EXPERT RESPONSE
You'll need a UNION query to produce a result set which contains
all the values from each of the 4 columns in one result set column.
Then you can do your "top N" query on the result set
(which is called a derived table when used as a subquery).
Note that "top N" logic varies from one database to the next; see
FIRST N rows, TOP N rows, LAST N rows, BOTTOM N rows...
Here's how it would look in SQL Server:
select top 10
Topics, source, sourcevalue
from (
select Topics
, 'XX' as source, XX as sourcevalue
from yourtable
union all
select Topics, 'YY', YY
from yourtable
union all
select Topics, 'ZZ', ZZ
from yourtable
union all
select Topics, 'RR', RR
from yourtable
) as dt
order by sourcevalue desc
Note UNION ALL instead of UNION, because we do not want the result set scanned for duplicates.
|