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 7754533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:20:00+00:00 2026-06-01T12:20:00+00:00

My oracle version is 10.2. It’s very strange when a scalar subquery has an

  • 0

My oracle version is 10.2.
It’s very strange when a scalar subquery has an aggregate operation.
my table named t_test looked like this;

t_id    t_name
 1       1
 2       1
 3       2
 4       2
 5       3
 6       3      

query string looked like this;

select t1.t_id,
       (select count(t_name)
         from (select t2.t_name 
                 from t_test t2 
                 where t2.t_id=t1.t_id 
                 group by t2.t_name)) a
from t_test t1

this query’s result is,

t_id  a
 1    3
 2    3
 3    3
 4    3
 5    3
 6    3

which is very weird,
take t1.t_id=1 for example,

select count(t_name)
 from (select t2.t_name 
         from t_test t2 
         where t2.t_id=1
         group by t2.t_name)

the result is 1,
somehow,the ‘where’ operator doesn’t work,the result is exactly the same as I put my query like this:

select t1.t_id,
       (select count(t_name)
         from (select t2.t_name 
                 from t_test t2 
                 group by t2.t_name)) a
from t_test t1

why?

  • 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-01T12:20:02+00:00Added an answer on June 1, 2026 at 12:20 pm

    Can you post a cut-and-paste from SQL*Plus showing exactly what query you’re running? The query you posted does not appear to be valid– the alias t1 is not going to be valid in the subquery where you’re referencing it. That makes me suspect that you’re simplifying the problem to post here but you’ve accidentally left something important out.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with x as (
      2    select 1 id, 1 name from dual union all
      3    select 2,1 from dual union all
      4    select 3,2 from dual union all
      5    select 4,2 from dual union all
      6    select 5,3 from dual union all
      7    select 6,3 from dual
      8  )
      9  select t1.id
     10        ,(select count(b.name)
     11            from (select t2.name
     12                    from x t2
     13                   where t2.id = t1.id
     14                   group by t2.name) b) a
     15*   from x t1
    SQL> /
                     where t2.id = t1.id
                                   *
    ERROR at line 13:
    ORA-00904: "T1"."ID": invalid identifier
    

    Presumably, it would be much more natural to write the query like this (assuming you really want to use a scalar subquery) where t1 is going to be a valid alias in the scalar subquery.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with x as (
      2    select 1 id, 1 name from dual union all
      3    select 2,1 from dual union all
      4    select 3,2 from dual union all
      5    select 4,2 from dual union all
      6    select 5,3 from dual union all
      7    select 6,3 from dual
      8  )
      9  select t1.id
     10        ,(select count(t2.name)
     11            from x t2
     12           where t2.id = t1.id) cnt
     13*   from x t1
    SQL> /
    
            ID        CNT
    ---------- ----------
             1          1
             2          1
             3          1
             4          1
             5          1
             6          1
    
    6 rows selected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have Oracle Server Oracle Version: 10.2.0.4.0 - 64bit. I like to connect to
When and how should table stats gathering be performed for Oracle, version 9 and
I am trying to parse a column of strings in Oracle (version 8i) to
Oracle 11g version of ODP.Net introduces the provider model objects (session state provider, identity
I have an Oracle server (version 9, I believe) and a MS SQL server
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
I have successfully installed Oracle 11g R2 version. I don't have good knowledge about
I'm using Oracle SQL Developer to query an Oracle DB (not sure which version
In my Oracle db I have records like this one: <ROOT> <Event> <Type>sldkfvjhkljh</Type> <ID>591252</ID>
I created SSIS will do task like get data from oracle to sql server.i

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.