General information
Title:
One to Many Join should return only 1 corr. record
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
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only