PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 24th, 2003, 12:19 AM
elef elef is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 45 elef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 28 m 27 sec
Reputation Power: 11
LEFT JOIN with AVG()

This is my query:

select b.bookID,b.title,b.author,b.connection,AVG(r.score) from books b LEFT JOIN book_ratings r on b.bookID=r.bookID group by r.bookID,b.bookID,b.title,b.author,b.connection order by UPPER(title);

I get the error:
Attribute unnamed_join.title must be GROUPed or used in an aggregate function

It works fine if I use a silent inner join, or if I replace the AVG with another field from that table and remove the GROUP BY clause.

Help? I don't understand the error given that b.title is part of the GROUP.

Reply With Quote
  #2  
Old February 24th, 2003, 09:09 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 26 m 39 sec
Reputation Power: 390
Presumably the problem is that you have order by on something that is not part of select clause in conjunction with group by. Use upper(title) in select clause and group by clause.

If postgres does not support expressions in group by you need to use a derived table (where you have the upper invocation) and group on that.

Last edited by swampBoogie : February 24th, 2003 at 11:15 AM.

Reply With Quote
  #3  
Old February 24th, 2003, 11:00 AM
elef elef is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 45 elef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 28 m 27 sec
Reputation Power: 11
When I read your reply I realized that I had been completely ignoring the UPPER(title) part of the query, and that it needed to be UPPER(b.title).

Doh! It's working great now; thanks for the help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > LEFT JOIN with AVG()

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap