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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:59:18+00:00 2026-06-12T13:59:18+00:00

I am writing a sql query in Oracle that’s something like this: SELECT *

  • 0

I am writing a sql query in Oracle that’s something like this:

 SELECT *
   FROM ( SELECT testid,
                 max(decode(name, 'longitude', stringvalue, NULL)) as longitude,  
                 max(decode(name, 'latitude', stringvalue, NULL)) as latitude
            FROM test_av 
           GROUP  BY testid
        ) av
  INNER JOIN ( 
                  SELECT id,
                          ((ACOS(
                                 SIN(16.15074 * 3.141592653 / 180) 
                                 * SIN(latitude * 3.141592653 / 180) 
                                 + COS(16.15074 * 3.141592653 / 180) 
                                 * COS(latitude * 3.141592653 / 180)
                                 * COS((-22.74426 - longitude)*3.141592653 / 180)
                          )*6373)) as distance
                    FROM test 

        ) t ON t.id = av.testid
  WHERE t.distance <= 100 

When I execute this query Oracle is saying 'longitude invalid identifier'. I was trying to access sub query alias, but the query is failing.

How can I access ‘alias’ of one sub query into another sub query?

  • 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-12T13:59:19+00:00Added an answer on June 12, 2026 at 1:59 pm

    If I’m understanding correctly what you’re trying to do, you don’t actually need the INNER JOIN, because you’re not taking any real information from test that’s not already on test_av. So, you can write:

    SELECT *
      FROM ( SELECT id,
                    longitude,
                    latitude,
                    ((ACOS( SIN(16.15074 * 3.141592653 / 180)
                            * SIN(latitude * 3.141592653 / 180)
                            + COS(16.15074 * 3.141592653 / 180)
                            * COS(latitude * 3.141592653 / 180)
                            * COS((-22.74426 - longitude) * 3.141592653 / 180)
                    )*6373)) AS distance
               FROM ( SELECT testid AS id,
                             max(decode(name, 'longitude', stringvalue, NULL)) as longitude,
                             max(decode(name, 'latitude', stringvalue, NULL)) as latitude
                        FROM test_av
                       GROUP
                          BY testid
                    )
           )
     WHERE distance <= 100
    ;
    

    If you want to explicitly ensure that you only get records that exist in test — that is, if you have records in test_av that don’t have parents in test, and you want to filter those out — then you can handle that in the innermost subquery, after your FROM test_av.

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

Sidebar

Related Questions

In a SQL query like this: SELECT * FROM MyTable WHERE x = 5;
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
I am writing an SQL query as a Javascript string like that: SQLdetail =
I am writing a SQL query that I would like to add a column
I'm writing a PHP script that builds an SQL query by concatenating the string
This is a situation I'm generally facing while writing SQL queries. I think that
Writing a SQL query that should return the average charges for a preceding 91
I am having trouble writing a sql query and I was hoping that someone
I am writing an SQL query in which that I will need to perform
I'm writing sql query to get post and only last comment of this post(if

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.