Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select command
Message
From
12/05/2015 05:58:34
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01619650
Message ID:
01619653
Views:
52
>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform