Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why do UNIONs in SQL statements take a long time?
Message
From
16/09/1999 12:05:20
 
 
To
15/09/1999 20:08:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00265270
Message ID:
00265511
Views:
17
>>Anybody know whether an SQL statement that uses multiple UNIONS is supposed to take a lot more time to execute versus issuing two or three separate SQL statement and manually joining the results?
>
>Generally speaking, no. In your case, yes.
>
>The UNION verifies each record to be only once in the result set. That means that you will never have two records with exactly the same field values (all fields) in a result set of a SELECT ... UNION ... statement.
>
>If you know that your individual results cannot include the same records or if you don't care, you can do as you said and it may be faster.
>
>But it will surely be MUCH slower if you verify record by record, field by field, as a UNION does.
>
>Vlad
>
>>I have an SQL statement that's basically 4 separate SQL's. On their own, each SQL statement takes about 3 seconds to run. But when I put them all together with the UNION clause, it takes about 2+ minutes to run instead. The output is the same whether I use the single SQL statement with UNIONS or run each of the 4 SQL statements separately and put them into a single table using something like APPEND FROM DBF("OneofMytables").

Just add the ALL adjective to the UNION and no effort will be made to remove duplicates. That will speed things up and probably work faster than 4 SELECTs and 3 APPENDs.
Previous
Reply
Map
View

Click here to load this message in the networking platform