Skip to content
Advertisement

Need to Pick Max Date when status = N otherwise No in MYSQL

I have a table which have records like this

I’m trying to get the Max Date for each ID which have STATUS = ‘N’. If I get MAX DATE and STATUS = ‘C’ then I don’t want that record.

Output :

SCRIPT :

But I’m not able to get desired output.

Advertisement

Answer

You can use NOT EXISTS:

If the column’s DATEADD data type is DATETIME or TIMESTAMP the last condition would be simpler:

See the demo.

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