Thread: Help with SQL
View Single Post
  #2  
Old 07-29-2005, 10:32 AM
TheTROLL TheTROLL is offline
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 103
Default Re: Help with SQL

Well, here it is (for SQL Server), but you have to punch the person who designed the database in the face. Hard.

/*
create table tester(col1 int, col2 int, col3 int, col4 int, col5 int)

insert into tester values(5,26,32,75,84)
insert into tester values(35, 5, 45, 78, 8)
insert into tester values(65, 65, 84, 26, 6)
insert into tester values(72, 26, 35, 5, 84)
*/

select col1, count(*) as occurs from
(select col1 from tester union all
select col2 from tester union all
select col3 from tester union all
select col4 from tester union all
select col5 from tester )as a group by col1 order by occurs desc,col1 desc
Reply With Quote