Jump to content

Unique search count


The Little Guy

Recommended Posts

I am trying to get the top 10 most popular searches from my database, I have the following:

 

select *, count(*) c FROM searches group by search_query order by c desc

 

This will get the top ten, but it will also get values for people that searched for the same thing 2+ times. So if 2 people search for "Monkey", and one person searches for it 5 times and the other searches for that 3 times, it should show it was searched for 2 times.

 

I am not sure how to format that query....

 

 

mysql> explain searches;
+--------------+------------------+------+-----+-------------------+----------------+
| Field        | Type             | Null | Key | Default           | Extra          |
+--------------+------------------+------+-----+-------------------+----------------+
| search_id    | int(10) unsigned | NO   | PRI | NULL              | auto_increment |
| ip           | int(10) unsigned | YES  |     | NULL              |                |
| search_query | varchar(100)     | YES  |     | NULL              |                |
| search_date  | timestamp        | YES  |     | CURRENT_TIMESTAMP |                |
+--------------+------------------+------+-----+-------------------+----------------+
4 rows in set (0.00 sec)

 

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.