[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Single Row Subquery Returns more than one row

Hi

I have an error in the code.

Please advise.


Leon
SELECT 		account_reference, ice_customer_id, key_type, parent_account_reference, parent_key_type, product_code, business_flag, start_date, end_date, account_type, account_name, domain
    FROM	   (SELECT 	    ice1.*, 
                            1 AS domain
                FROM        ice1.account ice1
                UNION ALL 
                SELECT 		ice2.*, 
                            2 AS domain
                FROM        ice2.account ice2)
    WHERE account_reference = (SELECT account_reference
                               FROM          (SELECT 	    ice1.*, 
                                                            1 AS domain
                                              FROM          ice1.base ice1
                                              UNION ALL 
                                              SELECT 		ice2.*, 
                                                            2 AS domain
                                              FROM          ice2.base ice2)
                               WHERE key_type IN (1,2,14,15)
                               AND (product_status = 'LI' 
                               OR (product_status = 'RC' AND start_date<SYSDATE)
                               OR (product_status IN('PL','PG') AND start_date>SYSDATE)))

Open in new window

0
SimpleIntelligence
Asked:
SimpleIntelligence
  • 2
1 Solution
 
RiteshShahCommented:
try now

SELECT          account_reference, ice_customer_id, key_type, parent_account_reference, parent_key_type, product_code, business_flag, start_date, end_date, account_type, account_name, domain
    FROM           (SELECT          ice1.*, 
                            1 AS domain
                FROM        ice1.account ice1
                UNION ALL 
                SELECT          ice2.*, 
                            2 AS domain
                FROM        ice2.account ice2) as t
    WHERE account_reference = (SELECT account_reference
                              FROM          (SELECT         ice1.*, 
                                                        1 AS domain
                                            FROM        ice1.base ice1
                
                                            UNION ALL 
                                            SELECT              ice2.*, 
                                                2 AS domain
                                            FROM        ice2.base ice2)  as t1
                                WHERE           key_type IN (1,2,14,15)
                                AND 
                                   (product_status = 'LI' 
                                OR (product_status = 'RC' AND start_date<SYSDATE)
                                OR (product_status IN('PL','PG') AND start_date>SYSDATE)))

Open in new window

0
 
RiteshShahCommented:
one more this, you may have to use

 WHERE account_reference IN

rather than.

 WHERE account_reference =
0
 
SimpleIntelligenceAuthor Commented:
Thanks Ritesh. Job done.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now