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
 Transact-SQL (2000)
 SELECT * when filtering with GROUP BY

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-12 : 09:15:28
Jake writes "I'm looking for something equivalent to this:
select *
from t~able
group by city, state

This query won't work because all fields in the 'select' have to be in the 'group by', but I need something that allows me to select all fields while ensuring unique city+state (ie- only one record with city="Park City" state="UT").

It seems like a pretty common type of query, but I haven't been able to find anything that do this. Any thoughts on how to do this?"

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-12 : 09:19:21
Only One record per City / State Combination ?
So if there r multiple records, with same City & State, what do u want to see ? Just any one randomly ?

Please Post some sample data and expected results

Srinika
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 09:39:33
Do you want one row for every city and state?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -