Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select TOP 1 on two fields
Message
De
04/02/2023 09:33:35
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
 
 
À
04/02/2023 07:46:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01686062
Message ID:
01686110
Vues:
39
>Dmitry,
>
>I follow such questions / discussions, because there are corners of SQL I am uncertain about or just ignorant. That said, In your shoes I'd never put the smart 1 query code in any of my apps
>
>The basic OP question was clear and defined 2 selection steps. Why not KISS and code in 3 queries ? That way, you can be certain that you will not run afoul implementation differences or updates on esoteric SQL and if somebody else (or a future Dmitry...) touches that code it will still resolve to the result specced.
>in Vfp there would be no need for even result cursor, better here as the JOIN is a filter
>SELECT MAX(DATE_FLD) As mD FROM MyTable into Array aT_Date
>SELECT MAX(ORDER_NO) AS mO FROM MyTable where DATE_FLD = aT_Date[1] into Array aT_Ord
>SELECT fields_needed_list   FROM MyTable;
>       where DATE_FLD = aT_Date[1] and ORDER_NO  = aT_Ord[1]
>
>There is no need for checking _tally if there is at least 1 record, as filter is a self join.
>So yes, ask questions- get smarter - but keep your code free of the answers ;-)
>
>my 0.02€
>thomas

And, as Tamar pointed out several times, don't trust _TALLY. Even as simple as
SELECT * from Cur1 into cursor Cur2
?_TALLY
might lie if some unexpected event fires.
Use
SELECT * from Cur1 into cursor Cur2 nofilter
?RECCOUNT("Cur2")
instead.
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform