Prev | SQL Engine Reference | Next |
AS
Remarks
Include an AS clause to assign a name to a select term or to a table name. You can use this name elsewhere in the statement to reference the select term. When you use the AS clause on a non-aggregate column, you can reference the name in WHERE, ORDER BY, GROUP BY, and HAVING clauses. When you use the AS clause on an aggregate column, you can reference the name only in an ORDER BY clause.
The name you define must be unique in the SELECT list.
Examples
The AS clause in the following statement instructs Pervasive.SQL to assign the name Total to the select term SUM (Amount_Paid) and order the results by the total for each student:
SELECT Student_ID, SUM (Amount_Paid) AS TotalFROM BillingORDER BY TotalGROUP BY Student_IDThe keyword AS is optional when used for table aliases as in this next example. When you use the AS clause on a table name in a FROM clause, you can reference the name in a WHERE, ORDER BY, GROUP BY, and HAVING clause.
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_IdFROM Person AS p, class AS cORDER BY c.Faculty_IdWHERE p.Id = c.Faculty_IdYou can rewrite this query without using the AS clause in the FROM clause as follows.
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_IdFROM Person p, class cORDER BY c.Faculty_IdWHERE p.Id = c.Faculty_IdOnce you establish a table alias, do not intermix the table name and its alias in a WHERE clause. The following does not work:
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_IdFROM Person p, class cORDER BY c.Faculty_IdWHERE Person.Id = c.Faculty_IdSee Also
Prev ANY |
Contents Up Check for Revisions | Next BEGIN [ATOMIC] |