SQL: SELECT statement

In a relational database, data is stored in tables. The Select statement allows you to retrieve records from one or more tables in your database. 

The reductive syntax for the Select statement is:

SELECT column_name 
INTO new_table
FROM derived_table
WHERE conditions
HAVING conditions
ORDER BY expression

Example #1

SELECT * 
FROM EmployeeAddressTable

This example demonstrates a very simple Select query, which uses * to select all of the fields in EmployeeAddressTable.

Example #2

SELECT FirstName 
FROM EmployeeAddressTable
WHERE State = 'Ohio'

By using the Where clause, you can focus your selection by specifying certain criteria to be met by the values. The above example returns the names of all employees who live in state Ohio.

Example #3

SELECT EmployeeStatisticsTable.Salary, EmployeeAddressTable.LastName 
FROM EmployeeStatisticsTable,EmployeeAddressTable
WHERE EmployeeStatisticsTable.EmployeeIDNo = EmployeeAddressTable.EmployeeIDNo

The result set would display the salary and employee name fields where the EmployeeIDNo value existed in both the EmployeeStatisticsTable and EmployeeAddressTable.

admin

admin

Leave a Reply

Your email address will not be published.