afridy
1
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.
SELECT id
FROM dn_buys
WHERE LEFT(sold_date
,4)=“2020”
ORDER BY id DESC
The above query does not give 107 on top
r937
2
SELECT MAX(id) AS highest_id
FROM dn_buys
WHERE YEAR(sold_date) = 2020
1 Like
afridy
3
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
afridy
5
Thank you !!!
converted to int and resolved!!
Thank every one for the great support.
afridy
6
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?
system
Closed
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.