Distnict serial no & Latest time

  • select SERIALNO, Max(TIME)

    from dbo.TASK A

    join dbo.Status B

    on A.TID=B.TID

    where A.ID in ('1111',2222')

    and A.TYPE='Pen'

    group by B.SERIAL_NO, B.TIME

    order by BM.TIME

    For this query I may get serial no duplicates but times are unique

    For that serial no, I have to find the recent time. But if I use group by, I am getting the wrong no

  • Remove TIME from GROUP BY.

    Try not to use reserved keywords for names.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Yes. I did

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply