Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:31:39+00:00 2026-06-07T22:31:39+00:00

I have a query like SELECT tran_number FROM table_a WHERE customer_id IN (SELECT customer_id

  • 0

I have a query like

SELECT tran_number
  FROM table_a WHERE customer_id IN
          (SELECT customer_id 
             FROM table_b
            WHERE customer_key = 89564
                  AND (   other_phn_area_code
                       || other_phnum_pfx_num
                       || other_phnum_sfx_num IN
                          (123456789)))
       AND phn_area_code || phnum_pfx_num || phnum_sfx_num IN (123456789)

The above code is working fine. The concern is with the inner query (copied inner query alone below)…

(SELECT customer_id 
                 FROM table_b
                WHERE customer_key = 89564
                      AND (   other_phn_area_code
                           || other_phnum_pfx_num
                           || other_phnum_sfx_num IN
                              (123456789)))

When i execute this query, i’m getting error as customer_id: invalid identifier. In real, table_b is not having any field named customer_id. If so, then how it is working, without any issue, when i use it as an inner query above.

Please help me to understand this.

Database details below

Oracle 11G Enterprise edition 11.2.0.2.0
PL/SQL Release 11.2.0.2.0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:31:41+00:00Added an answer on June 7, 2026 at 10:31 pm

    It’s a matter of scope. Oracle validates identifiers starting with the innermost sub-query and working outwards. If we add table aliases to your original query things might become clearer:

    SELECT t1.tran_number 
      FROM table_a t1
      WHERE t1.customer_id IN 
              (SELECT t1.customer_id  
                 FROM table_b t2 
                WHERE t2.customer_key = 89564 
                      AND (   t2.other_phn_area_code 
                           || t2.other_phnum_pfx_num 
                           || t2.other_phnum_sfx_num IN 
                              (123456789))) 
           AND t1.phn_area_code || t1.phnum_pfx_num || t1.phnum_sfx_num IN (123456789) 
    

    In effect, the outer query is using the sub-querty as a test for EXISTS, i.e. just checking for the existence of a given value of CUSTOMER_KEY and those other columns. If this is not what you want then you should change the column name in the sub-query. (And that’s a pretty good bet: you’re probably getting puzzling results from the main query and that’s why you’re investigating the sub-query in isolation).

    Using aliases in these scenarios is always good practice. If you had aliased the sub-query like this:

    ....
      WHERE t1.customer_id IN 
              (SELECT t2.customer_id  
                 FROM table_b t2 
                WHERE t2.customer_key = 89564 
    ....
    

    the error would have been immediately apparent.


    The SQL Reference does explain the operation of scope in sub-queries, but it’s hard to find. What it says is this:

    “Oracle resolves unqualified columns in the subquery by looking in
    the tables named in the subquery and then in the tables named in the
    parent statement”

    You can find a clearer explanation of scoping in the PL/SQL documentation; SQL sub-queries work in the same fashion. Find out more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like: SELECT ... FROM ... WHERE .. AND SomeID =
I have an query like: SELECT id as OfferId FROM offers WHERE concat(partycode, connectioncode)
I have a query like SELECT * FROM myTable WHERE key LIKE 'XYZ' The
In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like so : SELECT * FROM table WHERE premium =
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a query like this SELECT TOWN, NAME FROM CINEMA WHERE CITY_ID =
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.