mrknowledge Posted January 15, 2007 Share Posted January 15, 2007 Is there a way to search for the most common value in a column? Like if i have 5 rows, and 3 have the value='foo' in the third column, can i have it return that value without having to create a function?thanks Quote Link to comment Share on other sites More sharing options...
shoz Posted January 15, 2007 Share Posted January 15, 2007 [code]SELECTcolumn, COUNT(*) AS nFROMtablenameGROUP BYcolumnORDER BYn DESCLIMIT 1[/code]Note that if multiple values are repeated just as frequently the one selected will be somewhat random. Quote Link to comment Share on other sites More sharing options...
mrknowledge Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks, that did the trick. 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.