Jump to content

Recommended Posts

I am building a system with PHP and mysql that manages contests.  I have tables for contests, contest submissions, and contest votes.  I'm trying to get the top 10 records from the current contest for the number of votes a submission has and order the query results based on the number of rows in contest votes where the submission id in the votes table equals the submission id in the submissions table.  Here is the query I have.

 

                                SELECT sub.id, sub.title, sub.author_id, sub.attachment_id,
				vote.id, vote.author_id
			FROM contest_submissions AS sub
			LEFT JOIN contest_votes AS vote ON (vote.submission_id=sub.id)
			WHERE sub.contest_id = ".$contest['id']."
			ORDER BY COUNT(vote) DESC
			LIMIT 10

 

I'm not sure how to order the results because the error I'm getting says unknown column vote in where clause.  I'm guessing that's because it's trying to order by a column called vote when i just want to order it by the number of rows.  Anyone have any ideas?

Link to comment
https://forums.phpfreaks.com/topic/238533-left-join-help/
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.