Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Distinct rows using Union and obtaining count

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-05-25 : 08:38:50
Kristian writes "I saw your article about unions http://www.sqlteam.com/item.asp?ItemID=239 but was wondering if its possible to also obtain the count, i have a command like this

SELECT Genre1, Number=COUNT(*) FROM links GROUP BY Genre1 ORDER BY Number DESC

how can i add a second genre to the same table, and then pull the results into a recordest along with the count, and distinct genres to? Complicated, its been confusing me for a while now.

i.e. a table like
GENRE1 GENRE2
dance pop
rock dance
dance classical
rock dance

would return a recordset like
dance 4
rock 2
pop 1
classical 1

Please help, Its in a web enviroment and the command will get executed many times a day so it must be efficient."
   

- Advertisement -