maliary Posted January 19, 2008 Share Posted January 19, 2008 Hi people, I this SQL statement that is supposed to get the last row in a table $sql4="SELECT batch_nr FROM care_test_request_baclabor WHERE batch_nr LIKE '%".$branchID."' ORDER BY batch_nr DESC LIMIT 1"; The last row happens to have a batch_nr value of 1080 The second last row has a batch_nr value of 11322070 The query picks the second last row, why dosen't it pick the actual last one. Is this a problem with the ORDER BY clause ? Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/ Share on other sites More sharing options...
tinker Posted January 19, 2008 Share Posted January 19, 2008 hats the value of $branchID ? Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-443439 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 How is it stored, INT or VARCHAR? You want it as a INT. Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-443496 Share on other sites More sharing options...
Daniel0 Posted January 19, 2008 Share Posted January 19, 2008 There is no point in having an ORDER BY if you limit it to one row. Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-443507 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 How else can you only return 1 result if there are mutiple rows returned? There is no point in having an ORDER BY if you limit it to one row. Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-443524 Share on other sites More sharing options...
Daniel0 Posted January 19, 2008 Share Posted January 19, 2008 Ah, I see what he was trying to do now. Disregard what I said above. Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-443535 Share on other sites More sharing options...
maliary Posted January 20, 2008 Author Share Posted January 20, 2008 Tinker, The value of $branchID is 0. Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-444223 Share on other sites More sharing options...
Barand Posted January 20, 2008 Share Posted January 20, 2008 try SELECT batch_nr FROM care_test_findings_baclabor ORDER BY create_time DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-444506 Share on other sites More sharing options...
maliary Posted January 21, 2008 Author Share Posted January 21, 2008 That did it !! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/86756-solved-order-by-clausesomething-is-amiss-here/#findComment-445042 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.