Tell Me
 

Building Simple Queries

Previous previous|next Next Page

When Sheila writes a basic query, two mandatory clauses in the SELECT statement syntax are required: a SELECT clause and a FROM clause.

The SELECT statement syntax is displayed. The SELECT clause specifies the columns that you want to display. The FROM clause specifies the tables that contain those columns.

Syntax

SELECT [DISTINCT] * | column [alias], ...
 FROM table;

Example

select * from employees; 

You can use the projection capability of SQL to choose the columns in a table that you want to retrieve. You can retrieve selected columns or all columns from a table.

You can use the selection capability of SQL to choose the rows that you want to retrieve from a table. You can specify various criteria to select the rows that you want to see.

You can restrict the number of rows that are retrieved from the database by using a WHERE clause in a SQL statement. By inserting a WHERE clause into a SQL statement, you can specify a condition that must be met, and only the rows that meet the condition are returned.

When using a WHERE clause:

  • The WHERE clause directly follows the FROM clause in the SQL statement syntax
  • The WHERE clause consists of the WHERE keyword and a condition or conditions.
  • The condition in a WHERE clause specifies a comparison of values that limits the rows that are returned by a query