karimali831 Posted July 25, 2010 Share Posted July 25, 2010 Hi I'm trying to select borderbg, bg1, bg2 in my query WHERE cupID = highest value-1 if that make sense? $style = mysql_query("SELECT borderbg, bg1, bg2 FROM ".PREFIX."cup_baum WHERE cupID=''"); e.g. table: cupID: (auto_increment) 78 77 76 75 ... $style selects borderbg, bg1, bg2 WHERE cupID=77 because it has the highest value-1 in the table. (or second highest) Any help will be great Thanks Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/ Share on other sites More sharing options...
trq Posted July 26, 2010 Share Posted July 26, 2010 $style = mysql_query("SELECT borderbg, bg1, bg2 FROM ".PREFIX."cup_baum WHERE cupID=MAX(cupID)-1); Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/#findComment-1091109 Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 You can't use MAX() like that, and even if you could if you deleted a record it could potentially break the code. Instead you can try: $style = mysql_query("SELECT borderbg, bg1, bg2 FROM ".PREFIX."cup_baum ORDER BY cupID DESC LIMIT 1,1"); Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/#findComment-1091112 Share on other sites More sharing options...
trq Posted July 26, 2010 Share Posted July 26, 2010 You can use MAX like that, your right though about the potential to break if a record is removed. Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/#findComment-1091122 Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 Are you sure? I was curious as to which method would be faster so I was going to do a test, and I received an "invalid use of group function" error. I also recall encountering a similar problem when attempting to use MAX() in a similar situation a while ago. Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/#findComment-1091123 Share on other sites More sharing options...
trq Posted July 26, 2010 Share Posted July 26, 2010 Hmmm. I stand corrected. Sqlite returns 'misuse of aggregate function MAX()' Looks like it should work. Quote Link to comment https://forums.phpfreaks.com/topic/208864-where-clause/#findComment-1091141 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.