companyid boxid tableid time
1 1 1 11.55
1 2 1 11.58
1 1 1 12.00
1 1 1 12.05
2 1 1 8.00
2 1 1 8.05
2 2 3 9.05
2 2 3 9.10
3 1 5 13.00
3 1 5 13.05
sql query....
output
1 1 1 11.55
2 1 1 8.00
3 1 5 13.00
how i can i use distinct on company id basis here as on each row time is different
i want query where row should be selected on distinct company id basis and min time for that id
what query i should use
SQL Query
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Pravin MoreRank #1,419 · 1.2K reputationPosted Jan 22, 2012, 11:07 PM EST
below query will work perfect for your requirment...
select max(companyid) as companyid,max(boxid) as boxid,max(tableid) as tableid,min(time) as time
from YourTableName
group by companyid
try it.
Thanks,
Pravin.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 23, 2012, 12:58 AM EST
from the out put, ithink u required time on basis of company id , box id and table id.
if yes than try following query.
select companyid as companyid,boxid as boxid,tableid as tableid,min(time) as time
from YourTableName
group by companyid,boxid,tableid
hope this help.