Query/Table term confusion

From: JasonCook (anonymous_at_discussions.microsoft.com)
Date: 03/22/04


Date: Mon, 22 Mar 2004 13:56:11 -0800

Looking at http://www.databasejournal.com/features/mssql/article.php/3112381 the guy creates a table called Orders, then has the query
select OrderId, OrderDate, O.OrderAmt
        ,(select sum(OrderAmt) from Orders
                          where OrderID <= O.OrderID)
          'Running Total'
from Orders O

My question . . . what is the purpose of the "O"
Why does he specify O.OrderAmt yet doesn't use it anymore until the subquery? Then, why does he use it with O.OrderID in the subquery?



Relevant Pages

  • Re: Query/Table term confusion
    ... --lets assume freight as an order amount on the northwind sample database. ... select OrderId, OrderDate, O.freight ... The O is an alias given to the outer table of the query. ... the subquery and the outer query alias is used. ...
    (microsoft.public.sqlserver.mseq)
  • Re: SQL expression is too complex
    ... > From the Help for UPDATE - SQL: ... > "You can include one subquery in the SET clause to specify an expression. ...
    (microsoft.public.fox.helpwanted)
  • Re: DMAX equivalent
    ... That just means that you are aliasing the columns in the subquery x as ... CustomerID, OrderDate, i.e orderdate actually stands for max ...
    (microsoft.public.sqlserver.programming)
  • Re: Horizontal to vertical with distinct
    ... don't name the columns within a derived table subquery you must specify the ... David Portas ... SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL Division
    ... surround the subquery with brackets, ... however, is that you CANNOT, then have any brackets in your subquery. ... select OrderID, max ...
    (microsoft.public.access.queries)