Mysql Left Function and Order By

Hi guys,


in above table, i need to get the highest id of year 2020 sales.
i tried with below query, but the results seems not correct.

FROM dn_buys
WHERE LEFT(sold_date,4)=“2020”

The above query does not give 107 on top

SELECT MAX(id) AS highest_id
  FROM dn_buys
 WHERE YEAR(sold_date) = 2020
1 Like

Hi r937

sorry it did not work


and here see this query and resut

but problem is, same id column have move higest values than 99. see this pls

and finally table structure

Why is id a varchar? Sorting a varchar (for MAX) is Lexicographical, not numeric.

1 Like

Thank you !!!
converted to int and resolved!!

Thank every one for the great support.

Thank you to r937. That Year function is an extra piece of knowledge for me!

Will that YEAR() function still work as the OP stores the two dates in ‘text’ columns?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.