August 8, 2010 at 12:11 pm
How do you get firstname, lastname for the latest DATE?
Thanks.
create table computert1 (id int identity (1,1), firstname varchar(20), lastname varchar(20))
insert computert1 (firstname, lastname)
select 'daniel', 'wade' union all
select 'joe', 'walker' union all
select 'daniel', 'serious' union all
select 'sam', 'jordan'
create table computert2 (id int identity (1,1), dates datetime)
insert computert2 (dates)
select getdate() union all
select '2008-10-01' union all
select '2005-10-01'
August 8, 2010 at 1:39 pm
DECLARE @Date DATETIME
SELECT @Date = MAX(dates) FROM computert2
SELECT FirstName, Lastname, Dates As LatestDate
FROM computert1
INNER JOIN computert2
ON computert1.id = computert2.id
WHERE dates = @Date
-Lucky
August 8, 2010 at 1:42 pm
Without variable
SELECT FirstName, Lastname, Dates As LatestDate
FROM computert1
INNER JOIN computert2
ON computert1.id = computert2.id
WHERE dates = (SELECT MAX(dates) FROM computert2)
-Lucky
August 8, 2010 at 1:45 pm
SELECT TOP 1*
FROM
(SELECT FirstName, Lastname, Dates As LatestDate
FROM computert1
INNER JOIN computert2
ON computert1.id = computert2.id)tmp
ORDER BY tmp.LatestDate desc
August 8, 2010 at 10:27 pm
Thank you so much.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply