Fmdpa Posted January 25, 2011 Share Posted January 25, 2011 I'm stumped on how to do a query...or if I can do it.This is in the PHP file that processes a search engine auto-suggest box. It takes the current value of the input and finds keywords in the DB beginning with that combination of letters: SELECT * FROM keywords WHERE keyword LIKE 'p%' ..."p" represents the current value of the search box. It might return a result set that looks like this:PHPprogrammingPerlPOST variablesPHPpoor web designpresentationpopularpublic static class...etc.The duplicate of "PHP" was intentional. That leads me into what I want to do. I want to eliminate duplicate entries, but I want to group the result set by the most common entries and ORDER BY the most common entries DESC. That would make "PHP" end up at the top of the list. Is there some way I can create a column in the result set that contains a COUNT of duplicate results, then I could GROUP BY that column? Link to comment Share on other sites More sharing options...
birbal Posted January 25, 2011 Share Posted January 25, 2011 i think it will work... SELECT COUNT(keyword) as keyc,keyword FROM keywordWHERE keyword LIKE 'p%'GROUP BY keyword ORDER BY keyc DESC Link to comment Share on other sites More sharing options...
Fmdpa Posted January 25, 2011 Author Share Posted January 25, 2011 That's it! Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.