Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select command
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01619650
Message ID:
01619653
Vues:
51
>I'm trying to select out from a parent table to a child table. The child can have multiple entries but I want to return the line with the largest value. I've tried a couple of select combinations but I'm not getting the correct result
>
>PARENT
>1 Name1
>2 Name2
>3 Name3
>
>CHILD
>1 12 Code1
>2 19 Code2
>2 16 Code3
>3 10 Code4
>3 13 Code5
>
>I want the result to be
>Name1 Code1
>Name2 Code2
>Name3 Code5
>
>~M
SELECT Parent.Name,;
       Child.Code;
FROM Parent;
INNER JOIN (SELECT Child.ParentFld, Child.Code;
               FROM Child;
            INNER JOIN (SELECT ParentFld, MAX(IdFld) AS IdFld;
                               FROM Child;
                        GROUP BY ParentFld) Chld;
                  ON Child.ParentFld = Chld.ParentFld AND Child.IdFld = Chld.IdFld) Child;
       ON Child.ParentFld = Parent.IdFld
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform