I have a few queries I have to change according to an email I just got. I am gathering up some data from tables and when I put them all together, let's say I have a customer who purchased 200 wines and has purchased the most(yes...the winestore database), how do I just show him when I do the sort?
The original method I had used was to find the max's and sort in descending order, limiting it by 1.
EXAMPLE:
SELECT firstname, surname, MAX(qty*price) FROM customer, orders, items WHERE customer.cust_id=orders.order_id AND orders.cust_id=items.cust_id and orders.order_id=items.order_id GROUP BY firstname, surname ORDER BY Max(qty*price) DESC LIMIT 1;
That query might still be a little messed up, but I get the result I need I think. But is there another way to do this without using the order by desc limit 1 method? I think if I just get help on this one I'll be able to apply it to the others. I spent a couple hours every day working on the queries, and just a couple hours ago it hit me to use this method, and I just now go an email from the professor because other students asked the same thing, and he says it's no go.
Thanks!
The original method I had used was to find the max's and sort in descending order, limiting it by 1.
EXAMPLE:
SELECT firstname, surname, MAX(qty*price) FROM customer, orders, items WHERE customer.cust_id=orders.order_id AND orders.cust_id=items.cust_id and orders.order_id=items.order_id GROUP BY firstname, surname ORDER BY Max(qty*price) DESC LIMIT 1;
That query might still be a little messed up, but I get the result I need I think. But is there another way to do this without using the order by desc limit 1 method? I think if I just get help on this one I'll be able to apply it to the others. I spent a couple hours every day working on the queries, and just a couple hours ago it hit me to use this method, and I just now go an email from the professor because other students asked the same thing, and he says it's no go.
Thanks!