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

  • Home
  • SEARCH
  • 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 9119765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:28:25+00:00 2026-06-17T05:28:25+00:00

I use the same alias (RankedPrice) twice in my query. I expected that to

  • 0

I use the same alias (RankedPrice) twice in my query. I expected that to cause an error. But it worked well. Why does this happen ? I was expecting it throw a variable scope error like C++ or Java, but it does not happen.

select *
from
(select *, RANK() over(order by retailprice) as RankedPrice
from CurrentProducts) as RankedPrice
where RankedPrice = 5
  • 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-17T05:28:26+00:00Added an answer on June 17, 2026 at 5:28 am

    Because of the way that SQL works, you can never have any confusion about what type of object you’re referencing, in any particular reference.

    If you have SELECT a, ..., you know that a is a reference to a column. It can’t be a reference to a table, a database, a stored procedure, a UDF, etc.(*)

    If you have SELECT a.b, ..., you know that a is a reference to a table(+), and that b is a reference to a column.(*)

    So, there’s no logical reason to preclude a table from containing a column where both the table and the column have the same name.


    (*) – this applies in the SELECT clause. In the FROM clause, a single-part name can only be a table(+), a two-part name can only be schema + table, etc. But in each clause, the type of objects being referenced is always unambiguous.

    (+) – well, what I really mean here is a row source – a table, a view, a CTE. Something that, if you wanted to, you could construct as a table and use in its place in the query.


    As others have said, there’s also no obstacle to introducing the same alias in a subquery. But that’s not happening here, because we end up with an object that can (properly) be referenced as RankedPrice.RankedPrice.

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

Sidebar

Related Questions

If I want to use the alias in the same query how do I
I made a query that is joining the same table - users- twice, with
i got this mssql query... but then i want to use it in mysql..
I am trying to use same validation function for all my controls. But I
Previously, I have an app that uses core data. I use same store url
does someone knows how to use the same store for chart and for grid
I'm trying to use to use the same name for an alias as the
I have several websites that use the same base files, other than a couple
Careless use of templates can cause bloat. One way to avoid that bloat is
I have three tables that I use which has proved this problem to be

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.