Re: [GENERAL] How do I write this query? Distinct, Group By, Order By?

2010-10-06 Thread Min Yin
Yes that works. Thanks a lot! Now what if I want to get not only user_id, but the full record of the user, which is in another table called users. The following query doesn't seem to work select users.id, users.*, max(orders.order_time) from users join orders on users.id=orders.user_id grou

Re: [GENERAL] How do I write this query? Distinct, Group By, Order By?

2010-10-06 Thread Min Yin
Hi Yes that works too. Many Thanks! Now as you have probably , what I really want to get the full record of the user, which is in another table called users. The following query doesn't seem to work select users.id, users.* from users join orders on users.id=orders.user_id group by users.id

Re: [GENERAL] How do I write this query? Distinct, Group By, Order By?

2010-10-06 Thread Josh Kupershmidt
On Wed, Oct 6, 2010 at 3:34 AM, Min Yin wrote: >  Hi Yes that works too. Many Thanks! > > Now as you have probably , what I really want to get the full record of the > user, which is in another table called users. The following query doesn't > seem to work > > select users.id, users.* from users j

Re: [GENERAL] How do I write this query? Distinct, Group By, Order By?

2010-10-05 Thread Josh Kupershmidt
On Tue, Oct 5, 2010 at 10:26 PM, Min Yin wrote: >  Hi There, > > I have a table looks like this: > > (order_id, user_id, order_time) > > One user_id can have multiple orders with order_id as the primary key, now I > want to get a list of users, ordered by their latest order respectively, for > exa

[GENERAL] How do I write this query? Distinct, Group By, Order By?

2010-10-05 Thread Min Yin
Hi There, I have a table looks like this: (order_id, user_id, order_time) One user_id can have multiple orders with order_id as the primary key, now I want to get a list of users, ordered by their latest order respectively, for example, if user A has two orders, one on today, the other a mo