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.
| Author |
Topic |
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2011-06-30 : 12:01:59
|
| Hi members! I have the following simple table:TEL_NUMBER INIT_DATE MODEL4165551234 05/01/2011 NOKIA4165551234 02/18/2011 MOTOROLA4165551234 01/02/2011 SAMSUNG4165553999 06/01/2011 ACER4165553999 02/28/2011 APPLE4165553999 01/19/2011 LGI would like the Query to output just one distinct TEL_NUMBER and the MODEL based on the most recent INIT_DATE, so the output would be:4165551234 05/01/2011 NOKIA4165553999 06/01/2011 ACERCan you please tell me what I'm missing here?SELECT TEL_NUMBER, MAX(INIT_DATE), MODELFROM SOURCE_TABLE T1Thanks! |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-06-30 : 12:09:35
|
| You need to GROUP BY. This will give you the most recent init_date for each TEL_NUmber,Model combinationSELECT TEL_NUMBER, MAX(INIT_DATE), MODELFROM SOURCE_TABLE T1GROUP BY TEL_NUMBER,MODELJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|