Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving top dates for each customer from 2 tables
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01238535
Message ID:
01238544
Views:
10
>Hi,
>
>I have two cursors. Both have the same 3 fields. RO_num, item_date, item_descr. Each cursor already contains the top dates for each ro_num for that cursor.
>Now I need to retrieve the top date for each RO_num in both cursors. Sometimes cursor1 will have an RO_num that cursor2 doesn't and vice-versa. Matching ro_nums will never have matching dates. The date in one cursor will always be higher than the other.
>
>Any SQL statement that'll combine both cursors in one shot?
>
>Thanks,
>
>Marcel
SELECT RO_num, item_date, item_descr;
FROM (SELECT RO_num, item_date, item_descr;
             FROM Table1;
      UNION; 
      SELECT RO_num, item_date, item_descr;
             FROM Table2) Tbl1
INNER JOIN (SELECT RO_num, MAX(item_date) AS item_date;
                   FROM (SELECT RO_num, item_date;
                                FROM Table1;
                         UNION; 
                         SELECT RO_num, item_date;
                         FROM Table2) Tbl2
                   GROUP BY RO_num) Tbl3;
ON Tbl1.Ro_Num = Tbl3.Ro_Num AND Tb1l.item_date = Tbl3.item_date
(not tested)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform