4 Replies - 379 Views - Last Post: 30 November 2012 - 12:53 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] MySQL help - population

Posted 30 November 2012 - 12:32 PM

Hello, D.I.C.

I'm trying to run a query to see who's asked the most questions. The user information is in a separate table to the question information. I can run a MySQL query in phpMyAdmin which provides the groups - IE, one person has asked X amount of questions, another user has asked Y amount of questions - you get my gist?

This SQL code is simple: SELECT COUNT( * ) FROM polls GROUP BY polls.poll_author LIMIT 5; which does half of what I want to do. When I try a SQL code which I thought would work, I was disappointed and tried many methods to work around it. I tried SELECT COUNT( * ) FROM polls, users GROUP BY polls.poll_author LIMIT 5; but that only returned the "COUNT" field - not the user ID which is essentially what I want so I can differentiate who posted X amount of polls.

Also, when I try a SQL code without the COUNT function, like so SELECT * FROM polls, users GROUP BY polls.poll_author; it just shows me the users and their first question - not the amount of rows they have of questions.

I hope someone can help me out - this is bugging me a little :(/>/>/>/>

Many thanks, always appreciated.

~huzi

Solution
My MySQL Query should have been SELECT COUNT(polls.poll_author), users.user_id FROM users, polls WHERE users.user_id=polls.poll_author GROUP BY users.user_id;

~huzi

This post has been edited by huzi8t9: 30 November 2012 - 12:52 PM


Is This A Good Question/Topic? 2
  • +

Replies To: [SOLVED] MySQL help - population

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: [SOLVED] MySQL help - population

Posted 30 November 2012 - 12:35 PM

Select your values. Then call mysql_num_fields() to see how many fields were returned in the previous statement.
Was This Post Helpful? 0
  • +
  • -

#3 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: [SOLVED] MySQL help - population

Posted 30 November 2012 - 12:38 PM

View Postno2pencil, on 30 November 2012 - 07:35 PM, said:

Select your values. Then call mysql_num_fields() to see how many fields were returned in the previous statement.


I can find out how many questions they've asked using SELECT * FROM polls GROUP BY poll_author;. The problem I'm having is associating that information with specific users.

thank you for your fast reply.

~huzi
Was This Post Helpful? 0
  • +
  • -

#4 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: [SOLVED] MySQL help - population

Posted 30 November 2012 - 12:52 PM

SOLVED - please see first post.

Thanks again for your help

~huzi
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: [SOLVED] MySQL help - population

Posted 30 November 2012 - 12:53 PM

Awesome! Thank you for sharing your solution!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1