![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have a table that contains orders, but I only want to select the latest orders from every client. Every order has a client_id, so I tried this: SELECT * FROM `orders` ORDER BY date DESC GROUP BY client_id; However, that doesn't work. This does: SELECT * FROM `orders` GROUP BY client_id ORDER BY date DESC; But it doesn't return the latest orders from every client, it selects orders by unique clients and then sorts it by date. How can I get the result I want? Thank you! Jaap Haagmans |
#3
| |||
| |||
|
|
Hi, I have a table that contains orders, but I only want to select the latest orders from every client. Every order has a client_id, so I tried this: SELECT * FROM `orders` ORDER BY date DESC GROUP BY client_id; However, that doesn't work. This does: SELECT * FROM `orders` GROUP BY client_id ORDER BY date DESC; But it doesn't return the latest orders from every client, it selects orders by unique clients and then sorts it by date. How can I get the result I want? |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Thank you both. The term "strawberry query" is new to me, but it has helped me understand this. Great stuff! Jaap |

#6
| |||
| |||
|
|
On 11/11/2010 12:56 PM, jhaagmans wrote: Thank you both. The term "strawberry query" is new to me, but it has helped me understand this. Great stuff! Jaap That's because the term is specific to this newsgroup - from the famous poster "strawberry" who has been very eloquent on the subject. ![]() |
#7
| |||
| |||
|
|
On Thu, 11 Nov 2010 15:58:29 -0500, Jerry Stuckle wrote: On 11/11/2010 12:56 PM, jhaagmans wrote: Thank you both. The term "strawberry query" is new to me, but it has helped me understand this. Great stuff! Jaap That's because the term is specific to this newsgroup - from the famous poster "strawberry" who has been very eloquent on the subject. ![]() The method of strawberry reproduction via a runner to create a clone plant at another location is a happy coincidence. The two or more strawberry plants thusly connected are a very apt visualization of how one might represent the behavior of the query.... -- A way of life that is odd or even erratic but interferes with no rights or interests of others is not to be condemned because it is different. * * * * * * * * * * * * * * -- Chief Justice Warren E. Burger |
![]() |
| Thread Tools | |
| Display Modes | |
| |