General information
Category:
Coding, syntax & commands
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
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