I have no idea how can I find the lowest string in date-type
I will just find lowest month(by years in a table)
TableName
Id | M | D | Y |
=======================
1 | 01 | 22 | 2012 |
2 | 11 | 29 | 2012 |
3 | 12 | 30 | 2013 |
4 | 01 | 30 | 2011 | <--- this !
5 | 12 | 14 | 2012 |
PHP:
$sql = "SELECT * FROM TableName WHERE M=?? AND Y=??";
$selected = mysql_query($sql);
so $selected
should give me a result like "4/01/30/2011" (Id,M,D,Y)
Any?
SELECT min(concat(Y,M,D)) FROM TableName
Edit: This just looks nice and clean but it is kind of very bad answer, so please use this answer
Just use the ORDER BY
clauses:
SELECT * FROM TableName
ORDER BY Y ASC, M ASC, D ASC
More info here : http://www.tizag.com/mysqlTutorial/mysqlorderby.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With