JudgementDay Posted February 3, 2012 Share Posted February 3, 2012 I have a table with a row called id. In this table there are 15 records: id 1, id 2, id 3 etc. I want to select the record with the highest id, which would be 15 I was using this code: SELECT * FROM products ORDER BY id DESC LIMIT 1 ... but it selects 9, and not 15. Then I used this code: SELECT MAX(id) FROM products ... and this also only selects 9. To me, this suggests my table is not setup right for this to work. Does anyone know what could be going on? | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id | varchar(100) | YES | | NULL | | Quote Link to comment Share on other sites More sharing options...
trq Posted February 3, 2012 Share Posted February 3, 2012 You need to use an INT type if you expect it to sort properly. VARCHAR is for text. Quote Link to comment Share on other sites More sharing options...
JudgementDay Posted February 3, 2012 Author Share Posted February 3, 2012 I see. Now I understand data types. Thanks man! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.