Home > Blockchain >  How I can Select Multiple Column in subquery SQL?
How I can Select Multiple Column in subquery SQL?

Time:07-08

This is My Query:-

 SELECT ind_first_name, 
    ind_last_name, 
    ind_email,
    ind_domain,                 
    uom_start_date, 
    uom_end_date, 
    uom_active, 
    (SELECT arl_id, arl_name 
    FROM    application_role,
    role_individual_mapping                 
    WHERE   arl_id = rim_arl_id 
    AND     rim_ind_id = uom_ind_id
    AND     rim_org_id = uom_org_id
    AND     rim_active = 'Y'
    AND     arl_active = 'Y' 
    ) arl_id,arl_name
    FROM    individual,
            user_organization_mapping 
    WHERE   uom_ind_id = '5b58bdfc-ae5c-4a19-b742-eef3c879c835'
    AND     uom_org_id = 'c3cd6a0f-7c97-4422-8617-153ee31d8832'
    AND     ind_id = uom_ind_id;

I want to use SubQuery in My Query for Selecting Two columns. Can anybody help me with this I am new to SQL

CodePudding user response:

Use a JOIN instead of a subquery.

SELECT 
  i.ind_first_name, 
  i.ind_last_name, 
  i.ind_email,
  i.ind_domain,                 
  u.uom_start_date, 
  u.uom_end_date, 
  u.uom_active,
  a.arl_id,
  a.arl_name 
FROM    individual AS i
INNER JOIN user_organization_mapping AS uom 
  ON i.ind_id = u.uom_ind_id  
LEFT OUTER JOIN role_individual_mapping AS r 
  ON r.ind_id = u.ind_id AND r.org_id = u.uom_org_id
  AND r.rim_active = 'Y'
LEFT OUTER JOIN application_role AS a 
  ON a.arl_id = r.rim_arl_id
  AND a.arl_active = 'Y'
WHERE   u.uom_ind_id = '5b58bdfc-ae5c-4a19-b742-eef3c879c835'
AND     u.uom_org_id = 'c3cd6a0f-7c97-4422-8617-153ee31d8832'
  • Related