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:
01308533
Vues:
7
>Any suggestions or clues how I might optimize this SQL, it is running via ADO?
>
>lcPreviousId = ThisRecord.Id
>
>* Previous record:
>SELECT * FROM Master WHERE (Id < lcPreviousId) UNION ;
> SELECT * FROM Archive WHERE (Id < lcPreviousId) ;
> ORDER BY Id DESC
>
>* Next record:
>SELECT * FROM Master WHERE (Id > lcPreviousId) UNION ;
> SELECT * FROM Archive WHERE (Id > lcPreviousId) ;
> ORDER BY Id ASC
>
>Thsnks,
> Nick

Using derived tables you can combine both selects into one
select * from (select * From Master where ID < lcPreviousID UNION ALL
select * from Archive where ID < lcPreviousID order by ID Desc)
UNION ALL
select * from (select * From Master where ID > lcPreviousID UNION ALL
select * from Archive where ID > lcPreviousID order by ID ASC)
But what result do you want to achieve with this query - get all records except for current record?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform