Click here to Skip to main content
15,912,977 members
Home / Discussions / Database
   

Database

 
AnswerRe: Retrieving the lastest instance of a record Pin
Luc Pattyn20-Mar-10 3:17
sitebuilderLuc Pattyn20-Mar-10 3:17 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP20-Mar-10 3:32
professional#realJSOP20-Mar-10 3:32 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP20-Mar-10 4:15
professional#realJSOP20-Mar-10 4:15 
GeneralRe: Retrieving the lastest instance of a record Pin
Luc Pattyn20-Mar-10 4:23
sitebuilderLuc Pattyn20-Mar-10 4:23 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP20-Mar-10 5:02
professional#realJSOP20-Mar-10 5:02 
GeneralRe: Retrieving the lastest instance of a record Pin
i.j.russell20-Mar-10 8:48
i.j.russell20-Mar-10 8:48 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP21-Mar-10 2:01
professional#realJSOP21-Mar-10 2:01 
GeneralRe: Retrieving the lastest instance of a record Pin
i.j.russell21-Mar-10 2:32
i.j.russell21-Mar-10 2:32 
Try running this;

if object_id('tempdb..#TableA')is not null
	DROP TABLE #TableA
go 
if object_id('tempdb..#Metrics')is not null
	DROP TABLE #Metrics
go 

create table #TableA
(
	Id int,
	ItemType char(1),
	Title varchar(50),
	Description varchar(100)
)
go

create table #Metrics
(
	ID int,
	TableAId int,
	datevalue datetime
)
go

insert into #TableA (ID, ItemType, Title, Description) values (1, 'A', 'First Title', 'First Description');
insert into #TableA (ID, ItemType, Title, Description) values (2, 'A', 'Second Title', 'Second Description');
insert into #TableA (ID, ItemType, Title, Description) values (3, 'B', 'Third Title', 'Third Description');
go

insert into #Metrics (ID, TableAId, datevalue) values (1, 1, '2010-01-01');
insert into #Metrics (ID, TableAId, datevalue) values (2, 1, '2010-01-02');
insert into #Metrics (ID, TableAId, datevalue) values (3, 3, '2010-01-03');
insert into #Metrics (ID, TableAId, datevalue) values (4, 2, '2010-01-04');
insert into #Metrics (ID, TableAId, datevalue) values (5, 2, '2010-01-05');
insert into #Metrics (ID, TableAId, datevalue) values (6, 3, '2010-01-06');
insert into #Metrics (ID, TableAId, datevalue) values (7, 1, '2010-01-07');
insert into #Metrics (ID, TableAId, datevalue) values (8, 2, '2010-01-08');
insert into #Metrics (ID, TableAId, datevalue) values (9, 1, '2010-01-09');
insert into #Metrics (ID, TableAId, datevalue) values (10, 3, '2010-01-10');
insert into #Metrics (ID, TableAId, datevalue) values (11, 3, '2010-01-11');
insert into #Metrics (ID, TableAId, datevalue) values (12, 1, '2010-01-12');
go

SELECT	
		a.ID
		,a.itemType
		,a.Title
		,a.Description
		,m.DateValue
FROM #TableA a
left join
(
	select tableaid,
		MAX(datevalue) as datevalue
	from #Metrics
	group by tableaid
) m on m.tableaid = a.id
go

drop table #Metrics
go 
drop table #TableA
go

GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP21-Mar-10 10:41
professional#realJSOP21-Mar-10 10:41 
GeneralRe: Retrieving the lastest instance of a record Pin
i.j.russell21-Mar-10 11:28
i.j.russell21-Mar-10 11:28 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP21-Mar-10 12:24
professional#realJSOP21-Mar-10 12:24 
GeneralRe: Retrieving the lastest instance of a record Pin
i.j.russell21-Mar-10 12:45
i.j.russell21-Mar-10 12:45 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP22-Mar-10 0:05
professional#realJSOP22-Mar-10 0:05 
GeneralRe: Retrieving the lastest instance of a record Pin
i.j.russell22-Mar-10 0:13
i.j.russell22-Mar-10 0:13 
GeneralRe: Retrieving the lastest instance of a record Pin
#realJSOP21-Mar-10 2:26
professional#realJSOP21-Mar-10 2:26 
AnswerRe: Retrieving the lastest instance of a record [ SOLVED] Pin
Luc Pattyn20-Mar-10 4:49
sitebuilderLuc Pattyn20-Mar-10 4:49 
GeneralRe: Retrieving the lastest instance of a record [ SOLVED] Pin
#realJSOP20-Mar-10 6:22
professional#realJSOP20-Mar-10 6:22 
QuestionT-SQL - Select with relationships Pin
#realJSOP20-Mar-10 2:50
professional#realJSOP20-Mar-10 2:50 
AnswerRe: T-SQL - Select with relationships Pin
amer shammout20-Mar-10 4:25
amer shammout20-Mar-10 4:25 
AnswerRe: T-SQL - Select with relationships Pin
i.j.russell20-Mar-10 4:28
i.j.russell20-Mar-10 4:28 
QuestionSQL server encryption Pin
Central_IT19-Mar-10 6:00
Central_IT19-Mar-10 6:00 
QuestionRe: SQL server encryption Pin
Chris Meech19-Mar-10 8:20
Chris Meech19-Mar-10 8:20 
AnswerRe: SQL server encryption Pin
Jörgen Andersson19-Mar-10 8:59
professionalJörgen Andersson19-Mar-10 8:59 
GeneralRe: SQL server encryption Pin
Chris Meech19-Mar-10 11:26
Chris Meech19-Mar-10 11:26 
AnswerRe: SQL server encryption Pin
Jörgen Andersson19-Mar-10 8:56
professionalJörgen Andersson19-Mar-10 8:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.