Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing SQL UNION
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01308521
Message ID:
01308979
Views:
13
>Naiomi,
>
>Appoplogies I chopped about the example SQL and missed out a couple of rather relevent lines, should have been:
>
>* Move to Previous record
>cSQL =	"SELECT TOP 1 * FROM "_
>		& "(SELECT TOP 1 *  FROM Master WHERE " _
>		& "Id < '" & cLastId & "' " _
>		& "ORDER BY Id DESC) curMaster "_
>	& "UNION ALL "_
>	& "SELECT * FROM "_
>		& "(SELECT TOP 1 * FROM Archive WHERE " _
>		& "Id < '" & cLastId & "' " _
>		& "ORDER BY Id DESC) curArchive "_
>	& "ORDER BY Id DESC"
>
>
>All the best,

I see, it's much better now, but you still don't need the first SELECT TOP 1 since you're selecting TOP 1 in the derived table. Or do you think it may return multiple records in case of the same ID? The current SQL looks ambigious to me.

Do you want to return just one the most recent record from either Master or Archive and thus you added select TOP 1 to the first select? Doesn't look right to me...
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform