My sql query:
SELECT * FROM `electric_transaction`
WHERE `Current Date`=(SELECT MAX(STR_TO_DATE(`Current Date`, '%d/%m/%Y'))
FROM `electric_transaction`)
When I execute the above query, I get a list of warnings showing:
Warning: #1292 Truncated incorrect datetime value: '01/04/2021'
Warning: #1292 Truncated incorrect datetime value: '31/03/2021'...
I've even tried
SELECT * FROM `electric_transaction`
WHERE `Current Date`=(SELECT MAX(`Current Date`) FROM
`electric_transaction`)
But, it just shows all the records which don't even have the maximum date. How do I fetch only those records which have the maximum date?
Note: My Current Date
column is of type VARCHAR
and the dates are in d/m/Y
format
As suggested by @Akina this query works:
SELECT * FROM `electric_transaction`
WHERE `Current Date`=
(SELECT DATE_FORMAT(MAX(STR_TO_DATE(`Current Date`, '%d/%m/%Y')),
'%d/%m/%Y') FROM `electric_transaction`)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.