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 |
Lambik
Starting Member
13 Posts |
Posted - 2010-12-30 : 06:20:54
|
Hi guys I need some helpI have 2 table's.tableA with product, startdatetableB with product, startdateI want to have a query which return for all the products in both the tablesthe oldest startdate.contents:tableAprod startdateA 1 jun 2006A 5 sep 2009B 1 may 2007tableAprod startdateA 1 oct 2010B 1 okt 2001the query must returnprod startdateA 1 jun 2006B 1 okt 2001I can make the queries for the table's apart but I needone queury which returns the result for both the table'sLambik |
|
matty
Posting Yak Master
161 Posts |
Posted - 2010-12-30 : 06:27:55
|
[code]SELECT prod, startdateFROM( SELECT prod, startdate,ROW_NUMBER() over(PARTITION BY prod ORDER BY startDate) AS Rownum FROM ( SELECT prod, startdate from tableA UNION ALL SELECT prod, startdate from tableB )t) pWHERE p.Rownum = 1[/code] |
 |
|
Lambik
Starting Member
13 Posts |
Posted - 2010-12-30 : 07:46:25
|
matty, many many thanx it's working great |
 |
|
matty
Posting Yak Master
161 Posts |
Posted - 2010-12-30 : 23:37:17
|
welcome :) |
 |
|
|
|
|