Search code examples
sqlsql-servert-sqltable-alias

What does "foo" mean in this SQL Server Query?


for eg...

SELECT * 
  FROM ( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking,
                stud_id, 
                stud_name, 
                stud_mark 
           FROM tbl_student ) AS foo 
 WHERE ranking = 10

Here foo is present...actually what it does ?..


Solution

  • It is just an alias.

    Aliases help you reduce the amount of text you may have to type out when writing queries.

    For instance this:

    SELECT customer.Name, customer.OpenDate FROM customer
    

    Can be shortened to:

    SELECT c.Name, c.OpenDate FROM customer c
    

    In your example, it is a derived table (not a physical one) which now you can actually say:

    SELECT foo.someField rather then SELECT *