Site icon Nature Museum Pets Care

Return the Greater of The Fields Last Column in SQL

I am faced with the problem of returning the greater of the two values in the “entryId” field, that precedes the “|” mark. Each entryId field will have different numbers depending on the day, and I need to select the values that are the same, and have a higher number that precedes the “|” mark.

For example, I will need to select entryId =
‘800181373149|3’, ‘800181373112|3’, ‘800181373186|3’

and not ‘800181373186|1’

Here is what my code is:

    SELECT 
     [entryId]
    ,[startDate]
    ,[endDate]
    FROM [data]
    WHERE entryId LIKE '8001813731%';

Here is the output:

entryId startDate endDate
800181373149|3 2021-09-28T07:21:00-05:00 2021-09-28T16:03:00-05:00
800181373112|3 2021-09-28T05:21:00-07:00 2021-09-28T12:00:00-07:00
800181373186|3 2021-09-28T07:21:00-05:00 2021-09-28T14:00:00-05:00
800181373186|1 2021-09-28T07:21:00-05:00 NULL
Exit mobile version