» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2006, 05:10 PM
henry henry is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
henry is on a distinguished road
Default unable to get what i want

Hi,

I'm working on a poll script and I'm having difficulty getting the syntax right on this query. What I want to do is determine which poll_item was voted for the most.

I start out with:

Code:
SELECT i.item_name, count(v.vote_value)
FROM poll_items i LEFT JOIN poll_votes v
USING (item_id, poll_id)
WHERE i.poll_id=2
GROUP BY i.item_name
ORDER BY i.item_id;

This gives me a 2 column table with all the items for a particular poll and their scores. I want to select the row from this table that contains the max score. I keep getting 'Invalid use of group function' when I try to return a row. I am successful returning the max(count(v.vote_value)) without its associated item_name, but that's not useful .

thanx -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-02-2006, 05:12 PM
Garros Garros is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Garros is on a distinguished road
Default

Try this CODE

SELECT i.item_name, count(v.vote_value) as votes
FROM poll_items i LEFT JOIN poll_votes v
USING (item_id, poll_id)
WHERE i.poll_id=2
GROUP BY i.item_name
ORDER BY votes desc
limit 1

CHEERS -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to add posts to a phpbb table after moving servers. tanny MySQL Forums 3 02-13-2007 03:44 PM
unable to connect. Wmichelle MySQL Forums 1 09-28-2006 07:22 AM
unable to log on....? Juliaz MySQL Forums 1 08-15-2006 08:23 AM
unable to add or update rows; Chariti MySQL Forums 1 08-14-2006 06:32 AM
unable to pass any variables from the index venomous PHP Programming and Tips 1 08-10-2006 02:40 PM


All times are GMT. The time now is 09:49 AM.