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
 General SQL Server Forums
 New to SQL Server Programming
 Using MIN to display one record

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.PersonId
WHERE dbo.Person.DateOfDeath IS NULL AND dbo.Person.DateOfBirth IS NOT NULL
GROUP 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 1
dbo.Person.PersonId, dbo.Names.ConcatName, dbo.Person.DateOfBirth
FROM dbo.Person
JOIN dbo.Names ON dbo.Person.PersonId=dbo.Names.PersonId
WHERE dbo.Person.DateOfDeath IS NULL AND dbo.Person.DateOfBirth IS NOT NULL
ORDER BY dbo.Person.DateOfBirth

Best regards,

Devart Team
Go to Top of Page

marcyj
Starting Member

2 Posts

Posted - 2010-07-23 : 06:59:54
Thanks very much
Go to Top of Page
   

- Advertisement -