Skip to content
Advertisement

Remove Duplicate Time Zones From SELECT query

I need help removing duplicate time zone records from my select query without deleting them. The current result is as follows:

The table returns duplicate GMT start times for the same employee, the database appears to be duplicating the results based on different time zones.

I just want to remove the duplicate GMT Presence Start Times

Employee ID # 691 should have 1 row, same with 5681 and 1927. Can someone please help?

Advertisement

Answer

You can use a GROUP BY clause to give unique values of GMT Presence Start Time for each employees Presence in the log. You need to use an aggregation function on the Presence Start Time and Presence End Time functions; I’ve chosen MIN in my example, but you might want something else.

Output (for your sample data):

Demo on SQLFiddle

Alternatively you can use window functions on the Presence Start and End times:

Output:

Demo on SQLFiddle

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