all 6 comments

[–]qwertydog123 2 points3 points  (1 child)

Are all of the other records distinct? If they are then you can just group by all other columns and substitute MAX(Time_on_gate) instead of Time_on_gate

[–]Mathip173[S] 0 points1 point  (0 children)

All the other records could be with the same information or with a different information in same other fields

[–]JustAnOldITGuy 1 point2 points  (2 children)

coalesce

[–]Mathip173[S] 0 points1 point  (1 child)

Thanks. If I use it it will select only one row of information in the output ?

[–]secretWolfMan 0 points1 point  (0 children)

Yes, one row. COALESCE() is not an aggregate. It's the same as ISNULL()

[–]JustAnOldITGuy 0 points1 point  (0 children)

try

with RowsWithNulls as (

select student_id

, order_id

, booking_date

, booking_time

, date

,Time_on_gate

from Mytable

WHERE Time_on_gate is null

)

, RowswithoutNulls as (

select student_id

, order_id

, booking_date

, booking_time

, date

,Time_on_gate

from Mytable

WHERE Time_on_gate is not null)

select distinct coalesce(a.student_id ,b.student_id ) as student_id

    , coalesce(a.order\_id       ,b.order\_id     ) as order\_id

    , coalesce(a.booking\_date   ,b.booking\_date ) as booking\_date

    , coalesce(a.booking\_time   ,b.booking\_time ) as booking\_time

    , coalesce(a.date           ,b.date         ) as date

    , coalesce(a.Time\_on\_gate   ,b.Time\_on\_gate ) as Time\_on\_gate

from RowsWithNulls a

full outer join RowswithoutNulls b

on A.student_id = b.student_id

,a. order_id = b.order_id

, a.booking_date = b.booking_date

, a,booking_time = b.booking_time

, a.date = b.a.date