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 Link to comment https://forums.phpfreaks.com/topic/34264-most-common-column-data/ 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. Link to comment https://forums.phpfreaks.com/topic/34264-most-common-column-data/#findComment-161154 Share on other sites More sharing options...
mrknowledge Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks, that did the trick. Link to comment https://forums.phpfreaks.com/topic/34264-most-common-column-data/#findComment-161170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.