I have a temporary table like this.

Then I'm pivoting that table using following query and output attached.
SELECT *
FROM (
SELECT * from @tmpTable2
) AS SourceTable
PIVOT
(
max(timec)
FOR eventb
IN (
[Veh Reg Time],[Fitness ok time],[RFID Issue time],[MG-IN],[WB IN],
[MG-OUT], [WB OUT]
)
) AS PivotTableAlias
In here issue is for a one 'RegNo' there is multiple records. But I want only one row for a one 'RegNo'. How can I achieve this?


DISTINCTwill help you ORGROUP BY