Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT SQL Statement
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00506284
Message ID:
00508278
Views:
18
Dore & Cives

*** previous messges
>Select Table2.DivisionId FROM Table1, Table2
>Where Table2.DivisionName = Table1.DivisionName
>Into Cursor TmpCursor
>
>Would the above work?
Alternatively,
SELECT DivisionID FROM Table2 WHERE ;
DivisionName IN ;
(SELECT DivisionName FROM Table1)

In my opinion, this is preferable because you don't
have to qualify the field names with the table that
they belong to.
*** end previous

The "SELECT...FROM... WHERE... IN (subselect)" is also faster.

The first SQL statement is performing a join between the two tables and is therefore comparing all the join values in the two tables. The second SQL statment is collecting a subset of join values from Table2 and then performing a comparison of Table1's join values against the subset.

However, if there are duplicates of Table1.DivisionName a faster query would be:

SELECT DivisionId ;
FROM Table2 ;
WHERE DivisionName IN ;
(SELECT DISTINCT DivisionName ;
FROM Table1)...

In this query the subquery is collecting unique values of DivisionName, which will speed the query even more.

Regards,
Thom C.
Previous
Reply
Map
View

Click here to load this message in the networking platform