Practical No 6 Simple Select Statement
Practical No 6 Simple Select Statement
9
Simple Select Statement
Databases store data for later retrieval. Ever wondered how that is achieved? It's
the SELECT SQL command that does the job.
That's what it's all about, retrieving data from the database tables. It's part of the data
manipulation language that is responsible for query the data from the database.
It is the most frequently used SQL command and has the following general syntax
SELECT [DISTINCT|ALL ] { * | [fieldExpression [AS newName]} FROM tableName [alias] [WHERE condition
][GROUP BY fieldName(s)] [HAVING condition] ORDER BY fieldName(s)
SELECT is the SQL keyword that lets the database know that you want to retrieve
data.
[DISTINCT | ALL] are optional keywords that can be used to fine tune the results
returned from the SQL SELECT statement. If nothing is specified then ALL is assumed
as the default.
{*| [fieldExpression [AS newName]} at least one part must be specified, "*"
selected all the fields from the specified table name, fieldExpression performs some
computations on the specified fields such as adding numbers or putting together
two string fields into one.
FROM tableName is mandatory and must contain at least one table, multiple tables
must be separated using commas or joined using the JOIN keyword.
WHERE condition is optional, it can be used to specify criteria in the result set
returned from the query.
GROUP BY is used to put together records that have the same field values.
HAVING condition is used to specify criteria when working using the GROUP BY
keyword.
ORDER BY is used to specify the sort order of the result se
Select operation
The SELECT operation is used for selecting a subset of the tuples according to a
given selection condition. ... It is used as an expression to choose tuples which meet
the selection condition. Select operation selects tuples that satisfy a given predicate.
Project Operation
If the user is interested in selecting the values of a few attributes, rather than
selection all attributes of the Table (Relation), then one should go
for PROJECT Operation.
Where Clause
The WHERE clause is used to extract only those records that fulfill a specified condition.
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Example
SELECT * FROM Customers
WHERE Country='Mexico';
Try it Yourself »