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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-07-08 : 08:40:46
|
| i haveselect * from users LEFT OUTER JOIN D ON dbo.users.Registration = dbo.D.Registrationnow this works but d.registration can have more then one record with the same registration - how can i make the query always pull the last registration entered (highest id) where d.temporary=0 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-07-08 : 08:42:27
|
| create a subquery with your condition and join to thatselect ...from t1join (select ... where ... ) t1 on t1.id = t2.id_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-08 : 11:30:43
|
No need if you use the new ROW_NUMBER() function in SQL Server 2005SELECT <col list here>FROM ( SELECT u.<col list here>, ROW_NUMBER() OVER (PARTITION BY u.UserID ORDER BY d.Registration DESC) AS RecID FROM dbo.Users AS u LEFT JOIN dbo.D AS d ON d.Registration = u.Registration AND d.Temporary = 0 ) AS dWHERE RecID = 1 Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|