Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MySql MAX() in a WHERE clause

Tags:

sql

select

mysql

I have one table named tbservicecallallocation and below is data for that table.

enter image description here

From above data i want that of technician with their MAX AllocationTime. Below image shows what result i want.. enter image description here

Please help me to write MySQL SELECT query for retrieve above data.

like image 877
Vijay Avatar asked Jan 31 '26 21:01

Vijay


1 Answers

Have a sub-query to return each technician's max AllocationTime. Join with that result:

select t1.*
from tbservicecallallocation t1
join (select TechnicianIDF, max(AllocationTime) as MAxAllocationTime
      from tbservicecallallocation
      group by TechnicianIDF) t2
  on  t1.TechnicianIDF = t2.TechnicianIDF
  and t1.AllocationTime = t2.MAxAllocationTime

Optionally add ORDER BY clause at the end:

ORDER BY AllocationStatus DESC
like image 95
jarlh Avatar answered Feb 02 '26 14:02

jarlh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!