Schweb's Lounge Forum for general conversation, chit chat, or most topics that don't fit in another forum.

MySQL Query


Post Reply New Thread Subscribe

 
Thread Tools
Murlyn

 
Murlyn's Avatar
 
Member Since: Jun 11, 2003
Location: Mount Vernon, WA
Posts: 4,906
Murlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to all
Mac Specs: MacBook Pro 2.6 GHz Core 2 Duo 4GB RAM OS 10.5.2

Murlyn is offline
Ok guys, i just can't figure this one out. Ill give you the scenario... and hopefully someone can figure this one out for me.. it's got to be simple, but my brain isn't working apparently

We have a contests table, a entries table and a voting table

When a person submits a contest, then people can submit entries to that contest, so the index relationship would be contest.id to entry.contest_id and then the contest people can vote on the entry to their contest, so

contest.id connects to entry.contest_id and entry.id connects to vote.entry_id

Now it's easy to figure out how many people have responded to a contest:

select count(*) from entries where contest_id = '1'

But now how do I figure how many entries he has that he has not voted on? especially when others can vote on it, so it's not like if I did a left join there would be null values for the vote, there could be multiple matches, but none with that user's id.. I hope that makes sense.. so for example:

select * from entries e left join votes v where e.contest_id = '1'

if there are no votes then it will return the entries that have not been voted on and the votes values would all be null values.

But if there are votes for that entry by other people besides the person that created the contest, then it will return values for the votes, when what I need is just to find out the total number of entries to their contest that they have not voted on yet.

Any ideas? I would hate to do multiple queries
QUOTE Thanks
knightlie

 
knightlie's Avatar
 
Member Since: Mar 22, 2007
Location: UK
Posts: 1,463
knightlie is just really niceknightlie is just really niceknightlie is just really niceknightlie is just really nice
Mac Specs: Lenovo Z560 Hackintosh -:- '06 iMac -:- iPod Touch 2ndGen

knightlie is offline
You need to query the voting table - for each person, get the number of votes grouped by entry_id - you should get 0 or 1 for each of them. of the top of my head:

select count(*) from votes group by entry_id where person=<whatever>

That syntax is probably wrong, I usually use Access to build queries like this, but that should do what you're after.

[URL="http://beadia.net"]Beadia[/URL - Jewelry Business Management Software]
I judge you when you use poor grammar.

Last edited by knightlie; 07-13-2007 at 03:23 AM. Reason: Wrong table
QUOTE Thanks
Murlyn

 
Murlyn's Avatar
 
Member Since: Jun 11, 2003
Location: Mount Vernon, WA
Posts: 4,906
Murlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to allMurlyn is a name known to all
Mac Specs: MacBook Pro 2.6 GHz Core 2 Duo 4GB RAM OS 10.5.2

Murlyn is offline
Yeah I can't do it that way since that would be a massive amount of queries and I would like to do this in one fell swoop. For every contest there are many entries, for every entry there are several votes. So for one contest, I need to find out how many of the entries have I voted on already. And if I understand what you wrote correctly, I would need do a query to return all the entries and then do a query on each of the entries to find out if I have voted for that entry. If you have several thousand entries, then that's some serious overhead.. again if I understand you correctly
QUOTE Thanks
mynameis

 
Member Since: Sep 30, 2004
Posts: 3,378
mynameis is just really nicemynameis is just really nicemynameis is just really nicemynameis is just really nice

mynameis is offline
I am a little confused as to what you are asking, but I was thinking something like:
select count(*) from entry e where
not exists (select * from vote v where e.id = v.entryid)
and e.contest_id = '1'
QUOTE Thanks
knightlie

 
knightlie's Avatar
 
Member Since: Mar 22, 2007
Location: UK
Posts: 1,463
knightlie is just really niceknightlie is just really niceknightlie is just really niceknightlie is just really nice
Mac Specs: Lenovo Z560 Hackintosh -:- '06 iMac -:- iPod Touch 2ndGen

knightlie is offline
Quote:
Originally Posted by Murlyn View Post
Yeah I can't do it that way since that would be a massive amount of queries and I would like to do this in one fell swoop. For every contest there are many entries, for every entry there are several votes. So for one contest, I need to find out how many of the entries have I voted on already. And if I understand what you wrote correctly, I would need do a query to return all the entries and then do a query on each of the entries to find out if I have voted for that entry. If you have several thousand entries, then that's some serious overhead.. again if I understand you correctly
The query I suggested can be embedded in another query to work for all contests, you select each contest and the count of the query I gave, similar to (this is wrong):

select contest.*, count(<my query>) from contest

I'm sure you can do it, you just need to nest a few queries. You might even need to create a View (or whatever MySQLs equivalent it) and query that as an intermediate step.

[URL="http://beadia.net"]Beadia[/URL - Jewelry Business Management Software]
I judge you when you use poor grammar.
QUOTE Thanks

Post Reply New Thread Subscribe


« Wrong Address! | Mac Haters - Why so vicious? »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Fresh install of MySQL denies access to root IceLatte Web Design and Hosting 0 06-24-2007 05:04 PM
MySQL Configuration = :( jimz Web Design and Hosting 2 04-13-2006 07:25 AM
long shot: php mysql column represent query? gort Web Design and Hosting 1 01-22-2006 06:31 PM
Installing mySQl on Mac OS X sealey Web Design and Hosting 7 06-02-2005 10:45 PM
Removing MySQL from Panther 3.6 vawolf OS X - Operating System 0 12-07-2004 09:25 PM

All times are GMT -4. The time now is 11:55 PM.

Powered by vBulletin
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?