Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
An SQL Challenge (it's a challenge for me anyway)
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00055877
Message ID:
00056183
Views:
28
>
>Erik,
>
>I just tried the following example. It works.
>
>SELECT Test.name, Test.city;
> FROM test, test Test_a;
> WHERE Test_a.id <> Test.id;
> AND (Test.name = test_a.name;
> AND Test.city = test_a.city)
>
>TEST.DBF has the follow data
>
>ID NAME CITY
>1 JIM VANCOUVER
>2 JIM VANCOUVER
>3 JIM SEATTLE
>4 BILL VANCOUVER
>5 JANE TORONTO
>
>The result is two records
>
>JIM VANCOUVER
>JIM VANCOUVER
>
>Since both of Jim's records match the other.
>
>You can join a table using multiple fields and it is valid, so I believe that you are incorrect in saying that this is a circular relationship.
>
>Even if this isn't the solution to your problem, I still think this is a valid join and serves the purpose of finding duplicate name/city with a different unique id.
>
>I would like to hear from Dorris, Chuck, Mark and Barbara (or others) on this SQL question.

Yes, you can definitely join a table to itself, and you did it the right way. The second instance of the table has to have a different alias assigned to it andused throughout the statement. Your example should put Erik very close to the solution when combined with Barbara's example with an outer join.
Mark McCasland
Midlothian, TX USA
Previous
Reply
Map
View

Click here to load this message in the networking platform