9.1 - Chapter 6 - Simple Queries in SQL
9.1 - Chapter 6 - Simple Queries in SQL
Chapter 6
Simple Queries in SQL
Objectives
1 Bag concept
2 Projection in SQL
3 Selection in SQL
6 NULL values
1992 SQL-92 SQL2, FIPS 127-2 Major revision (ISO 9075), Entry Level SQL-92 adopted as FIPS 127-2.
1999 SQL:1999 SQL3 Added regular expression matching, recursive queries, triggers, support for procedural
and control-of-flow statements, non-scalar types, and some object-oriented features.
2003 SQL:2003 Introduced XML-related features, window functions, standardized sequences, and
columns with auto-generated values (including identity-columns).
2006 SQL:2006 ISO/IEC 9075-14:2006 defines ways in which SQL can be used in conjunction with
XML. It defines ways of importing and storing XML data in an SQL database,
manipulating it within the database and publishing both XML and conventional SQL-
data in XML form. In addition, it provides facilities that permit applications to integrate
into their SQL code the use of XQuery, the XML Query Language published by the
World Wide Web Consortium (W3C), to concurrently access ordinary SQL-data and
XML documents.
2008 SQL:2008 Defines more flexible windowing functions, clarifies SQL 2003 items that were still
unclear [1]
6.3 Transact SQL (T-SQL)
T-SQL
SQL
6.3 Sub-languages of T-SQL
T - SQL
DDL
(Data Definition Language)
DML
(Data Manipulation Language)
DCL
(Data Control Language)
6.3 Sub-languages of T-SQL
6.4 SELECT commands
A SELECT statement retrieves information from the database. Using a SELECT
statement, you can do the following:
• Projection: You can use the projection capability in SQL to choose the
columns in a table that you want returned by your query.
• Selection: You can use the selection capability in SQL to choose the
rows in a table that you want returned by a query (with WHERE clause)
• Joining: You can use the join capability in SQL to bring together data that
is stored in different tables by creating a link between them.
6.4 SELECT commands
FROM employees
If you use the ORDER BY clause, it must be the last clause of the SQL
statement.
Expression: Specifies a column on which to sort.
A sort column can be specified as a name or column alias (which can be
qualified by the table or view name), an expression, or a nonnegative
integer representing the position of the name, alias, or expression in
select list.
Multiple sort columns can be specified. The sequence of the sort
columns in the ORDER BY clause defines the organization of the sorted
result set.
Example: Ordering output
Exercise 1