Home page
 
 Home 
 ASP 
 PHP 
 SQL 
 HTML 
 JavaScript 
 Search 
 Contact 
 
Search
or browse popular tags
Subscription

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

SQL: SELECT statement

Print

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.


If you'd like to see how it works, enter SQL statement and press Execute
 




Tags:

Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments





Copyright © 2005-2014             www.WebCheatSheet.com All Rights Reserved.