Home » SQL & PL/SQL » SQL & PL/SQL » single row subquery returns more than one row (11g R2)
single row subquery returns more than one row [message #643568] Mon, 12 October 2015 05:30 Go to next message
manoj12
Messages: 210
Registered: March 2008
Location: India
Senior Member
Hi,

I am getting the below error in the below query .

select 'MTD'  as Denom_Text,(count(1)*8) as Count_1 from HRBO.DIM_PERIOD    
where cal_date>=to_date(   (select substr(WEEk_NO,1,3) from dim_date where weekend_date in (to_date('08/03/2015','mm/dd/yyyy')-1) )    
                                                ||'/01/'||substr('08/03/2015',7,10),'mm/dd/yyyy')    
                    and cal_date<=to_date('06/08/2015','mm/dd/yyyy')-1    
                    and replace(to_char(cal_date,'DAY'),' ','') not in ('SATURDAY','SUNDAY')    

Single row subquery returns more than one row


The reason for the error is that the above subquery which is having select statement is giving 2 records having SUBSTR(week_no,1,3) as JUL and SUBSTR(week_no,1,3) as AUGI wanted only the max row to be passed to
CAL_DATE >= AUG/01/2015

How to handle this error in subquery and the subquery should return only the max row which is AUG

Please appreciate your help sir

Regards
Re: single row subquery returns more than one row [message #643569 is a reply to message #643568] Mon, 12 October 2015 05:39 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
What's wrong with using max in the subquery?
Re: single row subquery returns more than one row [message #643570 is a reply to message #643569] Mon, 12 October 2015 05:56 Go to previous messageGo to next message
manoj12
Messages: 210
Registered: March 2008
Location: India
Senior Member
Hi Sir,

Thanks for the update.

The problem with using max in the subquery is the subquery is returning two rows of which one is JUL and the second value is AUG. if I use max in the subquery it is going to return JUL. But I need data of AUG month.Also the point is if subquery for month returns isOCT and NOV. In this case MAX value will be NOV instead of OCT.

Appreciate your help on this sir.
Re: single row subquery returns more than one row [message #643571 is a reply to message #643568] Mon, 12 October 2015 06:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

This query is UNREADABLE.
Use the appropriate type format to get the wanted order.

Re: single row subquery returns more than one row [message #643574 is a reply to message #643571] Mon, 12 October 2015 08:05 Go to previous message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
So convert the month name to the month number and max that.
Previous Topic: what is the main usage of execute immediate.
Next Topic: How to get weeknum for the given date
Goto Forum:
  


Current Time: Fri Jul 17 21:44:21 CDT 2026