Re: How to make correct join
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Tue, 4 Apr 2006 21:19:04 +0000 (UTC)
(jannoergaard@xxxxxxxxxxx) writes:
As I recall the statement it's something like this
Select distinct dbo.Account.AccountNo as AccountNo
On dbo.Groups.AccountFrom <= dbo.Account.AccountNo ANDFrom dbo.Account inner join dbo.Groups
dbo.Groups.AccountTo >= dbo.Account.AccountNo
Hope you have a solution for me. I have tried different ways but don't
seme to get it right.
This is certainly better, since it relieves you from the DISTINCT:
SELECT a.AccountNp
FROM dbo.Account a
WHERE EXISTS (SELECT *
FROM dbo.Groups g
WHERE a.AccountNo BETWEEN g.AccountFrom AND g.AccountTo)
But whether that really addresses your issue, I cannot tell, because
your posting was very clear.
If this query does not work out, I suggest that you post the following:
o CREATE TABLE statements for your tables.
o INSERT statements with sample data.
o The desired result from the sample.
This permits anyone who wants to answer to copy and paste into
a query tool and develop a tested query.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- Follow-Ups:
- Re: How to make correct join
- From: jazpar
- Re: How to make correct join
- References:
- How to make correct join
- From: jannoergaard
- Re: How to make correct join
- From: Jack Vamvas
- Re: How to make correct join
- From: jannoergaard
- How to make correct join
- Prev by Date: Re: String Comparison using "Score Method"
- Next by Date: Re: Are embedded views (Views within views...) evil and if so why?
- Previous by thread: Re: How to make correct join
- Next by thread: Re: How to make correct join
- Index(es):
Relevant Pages
|