Lab 11 DB
Lab 11 DB
LAB EXPERIMENT # 11
SQL ALIAS and Select TOP Clause
SQL Aliases
• SQL aliases are used to give a table, or a column in a table, a temporary name.
select CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country
AS Address FROM Customers;
The following SQL statement creates an alias named "Address" that combine four
columns (Address, PostalCode, City and Country)
The following SQL statement selects all the orders from the customer with CustomerID=4
(Around the Horn). We use the "Customers" and "Orders" tables, and give them the table
aliases of "c" and "o" respectively (Here we use aliases to make the SQL shorter).
SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders
AS o WHERE c.CustomerName='Around the Horn' AND
c.CustomerID=o.CustomerID;
Output”
The SELECT TOP clause is used to specify the number of records to return.
The SELECT TOP clause is useful on large tables with thousands of records. Returning a
large number of records can impact performance.
The following SQL statement selects the first three records from the "Customers" table (for
SQL Server/MS Access).
Output:
SELECT * FROM Customers FETCH FIRST 3 ROWS ONLY;
Output:
The following SQL statement selects the first 50% of the records from the "Customers" table
(for SQL Server/MS Access):
The following SQL statement selects the first three records from the "Customers" table,
where the country is "Germany" (for SQL Server/MS Access)
Output: