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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:00:35+00:00 2026-06-08T02:00:35+00:00

I have one sql script in that one table is used with two alias

  • 0

I have one sql script in that one table is used with two alias and make a JOIN on it
but I need to understand why and when it is needed to do so
please elaborate ?

SELECT

             ISNULL(MarketValue,0)   
        FROM
            (                  
            SELECT TOP 5

                Delta,
                MarketValue     
            FROM
                (
                SELECT DISTINCT

                   FormatNumber(SUM([CURRENT].MarkToMarket), 0, ',', 0) AS Delta,
                    AVG([CURRENT].Mark) * SUM([CURRENT].Position) AS NumericPosition,
                    FormatNumber(AVG([CURRENT].Mark) * SUM([CURRENT].Position)* CASE WHEN [CURRENT].SecurityType IN ('Equity','Equity Option') THEN 100 ELSE 1 END, 0, ',', NULL)  AS MarketValue
                FROM
                    NAV [CURRENT]
                    LEFT JOIN
                    NAV Compare ON
                    [CURRENT].PurchaseLotId = Compare.PurchaseLotId AND
                    Compare.Date = '2012-06-06'
                WHERE

                    [CURRENT].SecurityType not in ('Equity')
                GROUP BY

                ORDER BY
                    NumericDelta DESC
            ) Movers
        FOR XML PATH ('TR'), TYPE
        ) AS VARCHAR(MAX)
    )

Why it is used like  FROM
                    NAV [CURRENT]
                    LEFT JOIN
                    NAV Compare ON
                    [CURRENT].PurchaseLotId = Compare.PurchaseLotId AND
                    Compare.Date = '2012-06-06'

NAV is only one table then what is the purpose to do take two alias of same table NAV [CURRENT] and NAV Compare and use LEFT JOIN?

please elaborate me.

  • 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-08T02:00:38+00:00Added an answer on June 8, 2026 at 2:00 am

    You are comparing 2 records from the table

    You need two different alias’s to represent the two different records.

    So for example if you had a table called Employees: (Id, Name, ManagerId) where ManagerId is the Id of an Employee’s immediate manager

    ID    Name     ManagerId
    1      CEO        null
    2     YourBoss      1
    3      You          2
    

    and you wanted to run a query that selected you and the name of your boss:

    SELECT emp.Name, mgr.Name
    FROM Employees emp INNER JOIN Employees mgr on emp.ManagerId = mgr.Id
    WHERE emp.Id = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL script that acquires table names and creates trigger for those
I have a script that processes queued records in a SQL table in SQL
I have three files: one called sql.php witch has a class db that I
In SQL Server 2008: I have one table, and I want to do something
I have a few SQL (Select/Update/Insert) syntax that I will run inside PL/SQL one
I have a database in SQL Server 2008 and one particular table has information
I have a PostgreSQL table that is mostly a bridge table but it also
I have a script that generates an SQL query as text e.g. ... return
Hello I have two mysql tables one that holds username and password second that
I have one MYSQL table. In that table there is one column name SRNO

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.