title: How to select and alias data only from the column that contains a certain string in Oracle SQL
body: <p>I am working with address records in an Oracle db. Each row contains information on two parents. There are four columns for phone number types and four columns for numbers. The types are Other_No_Type_1, Other_No_Type_2, Other_No_Type_3, Other_No_Type_4 and any one of them might contain a value of either 'Name1:Mobile', 'Name2:Mobile', 'Father Work', or 'Mother Work', That value refers to the number in the next column (Other_No_1, Other_No_2, Other_No_3 or Other_No_4). I need to pull the Other_No_x value when Other_No_Type_x is equal to Name1:Mobile and alias it &quot;contact_1_mobile&quot; and pull Name2:Mobile and alias it &quot;contact_2_mobile&quot;. In my SELECT below, you can see that I've just written &quot;a.other_no_1 as contact_1_mobile&quot; for example, but actually that might be retrieving a work number or the Name2:mobile number. This is my first request for help to the forum, so I apologize for probably not presenting my question properly. Thank you for any help you can give. Here is my statement as it stands now:</p>
  <pre><code>SELECT final.* 
      FROM (
          SELECT 
          --Name 1 in P1 household
          a.id
          ,a.name1_web_user_id as contact_1_id
          ,a.name1_full_name as contact_1_name
          ,a.other_no_1 as contact_1_mobile (THIS IS MY PROBLEM. &quot;Other_No_1&quot; MAY NOT ACTUALLY BE THE NAME1:MOBILE NUMBER TYPE I NEED. THIS PROBLEM IS THE SAME IN EACH SECTION OF MY STATEMENT.)
          ,a.email as contact_1_email
         
          --Name 2 in P1 household
          ,a.name2_web_user_id as contact_2_id
          ,a.name2_full_name as contact_2_name
          ,a.other_no_2 as contact_2_mobile (PROBLEM: HERE I ACTUALLY NEED TO FIND THE COLUMN THAT CONTAINS THE &quot;Name2:Mobile&quot; NUMBER)
          ,a.EMAIL_2 as contact_2_email
              
      FROM rg_student s left outer join rg_addr a on s.id = a.id
                  WHERE  (
                  (a.addr_code='P1' AND a.rg_active = 'Y') AND ((a.name1_web_user_id is not null) OR (a.name2_web_user_id is not null))
                              AND a.id in(SELECT id from rg_student where student_group='Student')
                          )
      UNION
      
          SELECT 
          --Name 1 in P2 household
          a.id
          ,a.name1_web_user_id as contact_3_id
          ,a.name1_full_name as contact_3_name
          ,a.other_no_1 as contact_3_mobile (PROBLEM LINE)
          ,a.email as contact_3_email
          
          --Name 2 in P2 household
          ,a.name2_web_user_id as contact_4_id
          ,a.name2_full_name as contact_4_name
          ,a.other_no_2 as contact_4_mobile (PROBLEM LINE)
          ,a.EMAIL_2 as contact_4_email
              
      FROM rg_student s left outer join rg_addr a on s.id = a.id
                  WHERE  (
                          (a.addr_code='P2' AND a.rg_active = 'Y') AND ((a.name1_web_user_id is not null) OR (a.name2_web_user_id is not null))
                              AND a.id in(SELECT id from rg_student where student_group='Student')
                          )
           )final
      ORDER BY final.id
  </code></pre>