Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing SQL UNION
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01308521
Message ID:
01308979
Vues:
12
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform