Oracle Development
 
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 ForumsDatabasesOracle Development

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 September 19th, 2011, 10:09 AM
Lori J Lori J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 8 Lori J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 3 sec
Reputation Power: 0
Trouble with MAX function

I am having trouble retrieving the Max, latest date, from a table with a join to one another table and other fields from both.

I was able to get the MAX service_date grouped by id. But once I tried to add more fields to the query and another table it won't work.

Here is what I have:

select MAX(cs.service_date), cs.notes, cs.applicant_id,wr.program_code,wr.last_name,wr.first_name,wr.region_code,wr.status_cd

from cs join wr on cs.applicant_id=wr.applicant_id

where wr.status_cd='AC'

group by cs.applicant_id

Help????

Reply With Quote
  #2  
Old September 19th, 2011, 01:07 PM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
The reason for this is because when you use Group By, you must include all select fields in the Group By.

Below will run but it probably won't produce the results you are trying to achieve.

Code:
select	
	MAX(cs.service_date), 
	cs.notes, 
	cs.applicant_id,
	wr.program_code,
	wr.last_name,
	wr.first_name,
	wr.region_code,
	wr.status_cd
from cs 
join wr on cs.applicant_id=wr.applicant_id
where wr.status_cd='AC' 
group by cs.applicant_id,wr.program_code,wr.last_name,wr.first_name,wr.region_code,wr.status_cd

Reply With Quote
  #3  
Old September 19th, 2011, 02:46 PM
Lori J Lori J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 8 Lori J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 3 sec
Reputation Power: 0
I get an error message:

ORA-00979: not a GROUP BY expression

Last edited by Lori J : September 19th, 2011 at 02:51 PM. Reason: change error message

Reply With Quote
  #4  
Old September 19th, 2011, 03:38 PM
Lori J Lori J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 8 Lori J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 3 sec
Reputation Power: 0
I got it to work. Must be I had something wrong.

Thanks!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Trouble with MAX function

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