Doing a query with two Tables normaly is done by A.IDA=B.IDA
But also A.IDA>B.IDA is possible - but can give more than one join.
I have the following query:
SELECT * FROM TblA
LEFT JOIN TblB ON TblB.Begin > TblA.End
Now I want to get ONLY ONE joined record.
Is there an syntax like:
LEFT JOIN TOP 1 TblB ON TblB.Begin > TblA.End ?SQL Server 2000:
Select top N *
from table
order by column
Oracle 9i:
Select *
from
(select columns from table ORDER BY column)
where rownum = 1;|||Originally posted by r123456
SQL Server 2000:
Select top N *
from table
order by column
Oracle 9i:
Select *
from
(select columns from table ORDER BY column)
where rownum = 1;
Thank you. - But just selecting the top one of a table is not my problem.
I need the top 1 in the JOIN statement, because I want to join one table with onother by joining from the second table only the ONE next elder record.|||Select *
from
tableB tb
LEFT OUTER JOIN
(select top N * from tableA where condition) v1 on
v1.id = tb.id;
This query will join all records of tableB with the first record of the set V1.|||Originally posted by r123456
...
(select top N * from tableA where condition) v1 on
v1.id = tb.id;
This query will join all records of tableB with the first record of the set V1.
Sorry - but this doesn't help either
because if top 1 selects a record with another v1.id than tb.id I get no joined records although there IS one (but not on top of the list v1)
Or did I get something wrong...|||select *
from TblA
left outer
join TblB
on TblB.Begin > TblA.End
and TblB.Begin
= ( select max(Begin)
from TblB
where Begin > TblA.End )|||Originally posted by r937
select *
from TblA
left outer
join TblB
on TblB.Begin > TblA.End
and TblB.Begin
= ( select max(Begin)
from TblB
where Begin > TblA.End )
THAT WORKS !!!!!!
Thanks a lot !!!!!!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment