Created
January 11, 2013 02:21
-
-
Save nexneo/4507450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let me create some sample data, to show you why: | |
mid :: mday_no :: something | |
1 :: 37 :: apple | |
2 :: 37 :: banana | |
2 :: 38 :: canteloupe | |
Now consider the first query: | |
SELECT * FROM cb_main WHERE mid = '1' AND mday_no=(select max(mday_no)) | |
Okay, the select max(mday_no) will return a value of 38, right? So then that query becomes the same as | |
SELECT * FROM cb_main WHERE mid = '1' AND mday_no = 38 | |
And you can clearly see that there are NO RECORDS AT ALL that match that query. So you will get a blank recordset. | |
Now compare that to: | |
SELECT * FROM cb_main WHERE mid = '1' ORDER BY mday_no DESC limit 1 | |
That *WILL* return the record | |
1 :: 37 :: apple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment