OOps...
Try this..
select iid,distinct(did),lt,ln,ma
Main Topics
Browse All TopicsHi Experts,
I need help in a mysql query to get the correct result. I am looking for a single query to do this in one step
I have these in my table
lid did lt ln stime
1 1 4 5 2009-09-20 12:45:32
2 2 4 5 2009-09-20 12:46:32
3 2 4 5 2009-09-20 12:47:52
4 3 4 5 2009-09-20 12:48:12
5 1 4 5 2009-09-20 12:49:52
6 1 4 5 2009-09-20 12:50:12
I want the result like this
lid did lt ln stime
2 2 4 5 2009-09-20 12:46:32
4 3 4 5 2009-09-20 12:48:12
6 1 4 5 2009-09-20 12:50:12
In simple words I want distinct 'did' and rows which has highest 'stime'.
lid, did, lt, ln has int data type, stime is date/time
Hope its clear.
Thanks in advance.
kiranvj
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Unfortunately the above queries is not working.
this
select iid,did,lt,ln,max(stime) from tablename group by did
gives somewhat strange results
lid, did, lt, ln is from same row, but max(stime) is displayed from another row.
This is what i need.
all fields from table where did = 1 and stime is maximum (among all row which has did = 1)
all fields from table where did = 2 and stime is maximum (among all row which has did = 2)
all fields from table where did = 3 and stime is maximum (among all row which has did = 3)
Business Accounts
Answer for Membership
by: tonystarkPosted on 2009-09-25 at 06:02:09ID: 25422474
Try this...
ime from tablename
select iid,distinct(did),lt,ln,st
u can also do this like..
select * from table where iid in(2,4,6)