Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT - SQL avoiding duplicates?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00856923
Message ID:
00856926
Views:
16
Try this:
CREATE CURSOR cust (pk int, name c(10))
CREATE CURSOR orders (pk int, date d, custfk int)
INSERT INTO cust VALUES (1, "ADAMS")
INSERT INTO cust VALUES (2, "BROWN")
INSERT INTO cust VALUES (3, "COOPER")

INSERT INTO orders VALUES(1, DATE()-2, 1)
INSERT INTO orders VALUES(2, DATE()-1, 1)
INSERT INTO orders VALUES(3, DATE(), 1)

INSERT INTO orders VALUES(4, DATE()-2, 2)
INSERT INTO orders VALUES(5, DATE()-1, 2)
INSERT INTO orders VALUES(6, DATE(), 2)

INSERT INTO orders VALUES(7, DATE()-3, 3)

SELECT cust.pk, cust.name, MAX(date) FROM cust JOIN orders ON cust.pk = orders.custfk GROUP BY cust.pk, cust.name
>I have a two tables which essentially have a one to many relationship. Let's call the first one custmrs and the second one orders. I want to have a SELECT statement will return matching results that only shows the most recent order for each customer.
>
>I thought I could do something like this, but it doesn't work. I get a Group By clause is missing or invalid error message. What am I doing wrong?
>
>SELECT * FROM custmrs JOIN orders ON custmrs.clientid = orders.clientid INTO CURSOR csrTemp ORDER BY custmrs.clientid, orders.orddate DESC GROUP BY custmrs.clientid
>
>Thanks,
>Don
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform