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 |
|
galbrecht
Starting Member
17 Posts |
Posted - 2008-05-05 : 17:18:17
|
| Hi GuysI have a table with a field that holds telephone no's eg:Name , Day_Tel_NoGreg , 07 2376543Greg , 07 2456689some names have more than one telephone no.I would like to extract only the latest one (the top no). Can anyone shed some light on how to write this statement.ThanksGreg |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2008-05-05 : 17:30:24
|
| How do you find out which is the latest one? Is there a column which stores this information?ThanksKarunakaran |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-06 : 00:25:00
|
quote: Originally posted by galbrecht Hi GuysI have a table with a field that holds telephone no's eg:Name , Day_Tel_NoGreg , 07 2376543Greg , 07 2456689some names have more than one telephone no.I would like to extract only the latest one (the top no). Can anyone shed some light on how to write this statement.ThanksGreg
SELECT t.Name,t.Day_Tel_NoFROM(SELECT ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Day_Tel_No) AS RowNo,Name,Day_Tel_NoFROM YourTable)tWHERE t.RowNo=1 |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-05-06 : 03:14:48
|
| hi, you can try this if u have table_id in ur tableselect * from table where table_id in (select max(table_id) from table group by name)oktanx... |
 |
|
|
|
|
|