Jump to content

SQL Statement for top searched keywords.


virtuexru

Recommended Posts

OK, so when someone searches on my site, I add the keyword to a DB. Now I want to show the results as by the "Top 10 most searched keywords".. so my SQL to insert is this:

 

			   				   			
$kcount = "INSERT INTO search 
(id, keyword) 
VALUES 
('', '$keyword')";

mysql_query($kcount);					

 

so say I have "hummer" 3 times and "porsche" 4 times and "toyota" once.

 

How would I make an SQL statement to see the most used keyword (in this case, it would be porsche)?

 

I know this is probably really simple but I'm drawing a blank.

Link to comment
https://forums.phpfreaks.com/topic/123965-sql-statement-for-top-searched-keywords/
Share on other sites

SELECT DISTINCT keyword, COUNT(*) AS count FROM search GROUP BY keyword ORDER BY count DESC LIMIT 1

 

Although it would be better if your table was like this

table search
id, keyword, count
1, hummer, 3
2, porsche, 4
3, toyota, 1

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.