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 |
|
marcyj
Starting Member
2 Posts |
Posted - 2010-07-23 : 04:58:14
|
I am trying to retrieve only one record; the oldest person still alive and then use fields from 2 tables. The query shows everyone rather than a single record so I have to order it to get the record that I want. Is there any way to display just that record? Thanks...quote: SELECT dbo.Person.PersonId, dbo.Names.ConcatName, MIN(dbo.Person.DateOfBirth) AS 'DateOfBirth' FROM dbo.Person JOIN dbo.Names ON dbo.Person.PersonId=dbo.Names.PersonIdWHERE dbo.Person.DateOfDeath IS NULL AND dbo.Person.DateOfBirth IS NOT NULLGROUP BY dbo.Names.ConcatName, dbo.Person.DateOfBirth, dbo.Person.PersonId ORDER BY dbo.Person.DateOfBirth
|
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-07-23 : 05:51:08
|
| Hello,You can try this:SELECT TOP 1dbo.Person.PersonId, dbo.Names.ConcatName, dbo.Person.DateOfBirthFROM dbo.PersonJOIN dbo.Names ON dbo.Person.PersonId=dbo.Names.PersonIdWHERE dbo.Person.DateOfDeath IS NULL AND dbo.Person.DateOfBirth IS NOT NULLORDER BY dbo.Person.DateOfBirthBest regards,Devart Team |
 |
|
|
marcyj
Starting Member
2 Posts |
Posted - 2010-07-23 : 06:59:54
|
| Thanks very much |
 |
|
|
|
|
|