3 Replies - 306 Views - Last Post: 02 April 2013 - 02:24 PM Rate Topic: -----

#1 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 330
  • Joined: 11-July 07

[SOLVED] Populating most popular value

Posted 02 April 2013 - 01:32 PM

Hello, D.I.C.

I have a little question, and since I've been trying hundreds (almost... or slight exaggeration) of queries, I decided to give in, since MySQL is not my strong point - I know SELECT * and some basic JOIN - that's it.

I have a theme system on my website - each theme is saved in the database and the primary key is an INT; each users theme is set to 0 by default which is the sites theme - whenever that is changed, their theme is changed. However, if they set it (currently 1-8), then that's it, unless they choose to opt back for the site theme.

I want to be able to select the most popular theme; I tried a query

SELECT DISTINCT (
user_theme
) AS uTheme
FROM users
ORDER BY uTheme DESC 



and another

SELECT COUNT(
DISTINCT(user_theme)
), DISTINCT (
user_theme
) AS uTheme
FROM users
ORDER BY uTheme DESC



It's fair to say that neither of those queries worked. I hope that by those, that someone will get my jist and be able to help me.

Thanks in advanced, any help appreciated.

~huzi

This post has been edited by huzi8t9: 02 April 2013 - 03:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [SOLVED] Populating most popular value

#2 GrooN  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 20
  • Joined: 27-February 13

Re: [SOLVED] Populating most popular value

Posted 02 April 2013 - 01:52 PM

Try the following query and see if that does the job :)/>

select user_theme, count(user_theme) as num
from users
group by user_theme
order by num desc



The first entry will be the most frequent. Whereas user_theme of course will be the theme id, and num will be the number of times it is found. That way you'll have a list of all the used themes ordered by how many times it exist.

This post has been edited by GrooN: 02 April 2013 - 02:05 PM

Was This Post Helpful? 1
  • +
  • -

#3 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 330
  • Joined: 11-July 07

Re: [SOLVED] Populating most popular value

Posted 02 April 2013 - 02:14 PM

You, sir, are a wizard! Thank you very much!

~huzi

This post has been edited by Dormilich: 02 April 2013 - 10:19 PM

Was This Post Helpful? 0
  • +
  • -

#4 GrooN  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 20
  • Joined: 27-February 13

Re: [SOLVED] Populating most popular value

Posted 02 April 2013 - 02:24 PM

hehe, no problem :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1