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 |
|
hansen
Starting Member
2 Posts |
Posted - 2006-08-18 : 04:31:30
|
| Hi,Is it posible to use TOP 1 on the table HRMVirtualNetworkHistory?SELECT dbo.Empltable.EmplId, dbo.HRMVirtualNetworkHistory.hrmOrganizationId, dbo.HRMOrganization.descriptionFROM dbo.EMPLTABLE INNER JOIN dbo.HRMVirtualNetworkTable ON dbo.emplTable.EmplId = dbo.HRMVirtualNetworkTable.reference INNER JOIN dbo.HRMVirtualNetworkHistory ON dbo.HRMVirtualNetworkTable.hrmVirtualNetworkId = dbo.HRMVirtualNetworkHistory.hrmVirtualNetworkId LEFT OUTER JOIN dbo.HRMOrganizationON dbo.HRMOrganization.hrmOrganizationId = dbo.HRMVirtualNetworkHistory.hrmOrganizationId |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-18 : 04:40:50
|
Yes, if you make it a derived table.SELECT dbo.Empltable.EmplId, dbo.HRMVirtualNetworkHistory.hrmOrganizationId, dbo.HRMOrganization.descriptionFROM dbo.EMPLTABLEINNER JOIN dbo.HRMVirtualNetworkTable ON dbo.emplTable.EmplId = dbo.HRMVirtualNetworkTable.referenceINNER JOIN ( SELECT TOP 1 hrmVirtualNetworkId FROM dbo.HRMVirtualNetworkHistory ORDER BY SomeColumn ) derivedtable ON derivedtable.hrmVirtualNetworkId = dbo.HRMVirtualNetworkTable.hrmVirtualNetworkId LEFT JOIN dbo.HRMOrganization ON dbo.HRMOrganization.hrmOrganizationId = dbo.HRMVirtualNetworkHistory.hrmOrganizationId Peter LarssonHelsingborg, Sweden |
 |
|
|
hansen
Starting Member
2 Posts |
Posted - 2006-08-18 : 04:49:55
|
Thank you |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-18 : 11:24:52
|
| Also note that whenever subquery uses TOP, result should be ordered by a columnMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|