user2093576 user2093576 - 7 months ago 14
SQL Question

Sql - handling single-row subquery returns more than one row

In my following query :

select * from TABLE1 where
to_char( created_date, 'Month' ) = (select quarter_month from TABLE2 where quarter_name = 'Q2')


I need to fetch all the records from table1 which falls under the months of Q2,

But the above query is giving me ORA-01427: single-row subquery returns more than one row.

How do i fetch the required result?

Answer

Use in:

select *
from TABLE1 
where to_char(created_date, 'Month') in (select quarter_month
                                         from TABLE2
                                         where quarter_name = 'Q2'
                                        );