Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One to Many Join should return only 1 corresponding record
Message
From
20/08/1999 14:05:13
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
One to Many Join should return only 1 corresponding record
Miscellaneous
Thread ID:
00255979
Message ID:
00255979
Views:
38
I have two tables A and B where A contains field1 and field2 and table B contains field3 and field4. What I want is to get the corresponding value of field4 from table B. I tried:

select distinct A.field1, B.field4 from A, B where A.field1 = A.field3

But since A.field1 has many occurences in B.field3 the result set returns records I do not want. And so it's slow. It appears like this:

field1 field4
0001 abc
0001 abc
0002 cde
0002 cde
0002 cde

If i change the sql statement to:

select distinct A.field1, B.field4, B.field5 from A, B where A.field1 = A.field3

I get:

field1 field4 field5
0001 abc 01
0001 abc 02
0002 cde 11
0002 cde 12
0002 cde 13

How can I construct a query that would return:

field1 field4
0001 abc
0002 cde

Again, thanks for the info :)

Ramon
Next
Reply
Map
View

Click here to load this message in the networking platform