Skip to content
Advertisement

MySQL get the matching rows for the min and max columns as in a single row

Hellow experts ! I have a timesheets table as below

timesheets table

I am using the following query to get the in and out times of the employees

and I get the desired output as expected as below

Now i need to get the device_id’s of the the in and out records as time_in_device_id and time_out_device_id. How to achieve that ?

Advertisement

Answer

Do not use between with times. The following is simpler and more accurate.

MySQL does not offer “first()” and “last()” aggregation functions. However, you can use string manipulation to do what you want:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement