Unix Technical Forum

Why doesn't this query work? Puzzle to hard for me to crack

This is a discussion on Why doesn't this query work? Puzzle to hard for me to crack within the pgsql Novice forums, part of the PostgreSQL category; --> This query works as I want it to: SELECT sum(cutoffuohands) AS HANDS, sum(cutoffuopfr) AS pfr FROM compiledplayerresultspositionaction JOIN compiledresults ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:51 PM
sdger erger
 
Posts: n/a
Default Why doesn't this query work? Puzzle to hard for me to crack

This query works as I want it to:

SELECT sum(cutoffuohands) AS HANDS, sum(cutoffuopfr) AS pfr
FROM compiledplayerresultspositionaction
JOIN compiledresults
ON compiledplayerresultspositionaction.compiledplayer results_id =
compiledresults.compiledplayerresults_id
JOIN players
ON compiledresults.player_id = players.player_id
WHERE playername = 'Robert'

It returns the number of "cutoffuohands" and the number of "cutoffuopfr" for
the player Robert.

--------------------------------------------------------

But this similar query does not work as I want it to do:

SELECT sum(cutoffuohands) AS HANDS, sum(cutoffuopfr) AS pfr
FROM compiledplayerresultspositionaction
JOIN compiledresults
ON compiledplayerresultspositionaction.compiledplayer results_id =
compiledresults.compiledplayerresults_id
JOIN players
ON compiledresults.player_id = players.player_id
WHERE playername = 'Robert'


I want it to return all the "cutoffuohands" and "cutoffuopfr" for all
players not named Robert. But it returns unreasonable numbers.

Unfortunately I don't know much about the inner workings of the database and
unfortunately I'm only a novice with SQL so I haven't been able to figure
out how to fix the second query. I hope you guys here on the mailing list
can take a lot at this and see if you can figure it out.

Thanks!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:51 PM
Frank Bax
 
Posts: n/a
Default Re: Why doesn't this query work? Puzzle to hard for me tocrack

These queries are identical!

I'm guessing your query works because there is only one player named
Robert. If there were more than one Robert; the query will likely also
produce incorrect results.

IAC, try adding "GROUP BY players.player_id".




sdger erger wrote:
> This query works as I want it to:
>
> SELECT sum(cutoffuohands) AS HANDS, sum(cutoffuopfr) AS pfr
> FROM compiledplayerresultspositionaction
> JOIN compiledresults
> ON compiledplayerresultspositionaction.compiledplayer results_id =
> compiledresults.compiledplayerresults_id
> JOIN players
> ON compiledresults.player_id = players.player_id
> WHERE playername = 'Robert'
>
> It returns the number of "cutoffuohands" and the number of "cutoffuopfr"
> for the player Robert.
>
> --------------------------------------------------------
>
> But this similar query does not work as I want it to do:
>
> SELECT sum(cutoffuohands) AS HANDS, sum(cutoffuopfr) AS pfr
> FROM compiledplayerresultspositionaction
> JOIN compiledresults
> ON compiledplayerresultspositionaction.compiledplayer results_id =
> compiledresults.compiledplayerresults_id
> JOIN players
> ON compiledresults.player_id = players.player_id
> WHERE playername = 'Robert'
>
>
> I want it to return all the "cutoffuohands" and "cutoffuopfr" for all
> players not named Robert. But it returns unreasonable numbers.
>
> Unfortunately I don't know much about the inner workings of the database
> and unfortunately I'm only a novice with SQL so I haven't been able to
> figure out how to fix the second query. I hope you guys here on the
> mailing list can take a lot at this and see if you can figure it out.
>
> Thanks!



---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com