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
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

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.