Unions in subqueries  Constant expressions

Chapter 9: SQL Derived Tables

Renaming columns with SQL derived tables

If a derived column list is included for a SQL derived table, it follows the name of the SQL derived table and is enclosed in parentheses, as in the following example:

select dt_b.book_title, dt_b.tot_sales
   from (select title, total_sales
            from titles) dt_b (book_title, tot_sales)
   where dt_b.book_title like "%Computer%"

Here the column names title and total_sales in the derived table expression are respectively renamed to book_title and tot_sales using the derived column list. The book_title and tot_sales column names are used in the rest of the query.

NoteSQL derived tables cannot have unnamed columns.





Copyright © 2005. Sybase Inc. All rights reserved. Constant expressions

View this book as PDF