10 - Chapter 6 - Simple Queries in SQL
10 - Chapter 6 - Simple Queries in SQL
Session 11
Chapter 6 – The Database Language SQL
Simple Queries in SQL
Objectives
1 SQL Overview
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]
Transact SQL (T-SQL)
SQL
Sub-languages of T-SQL
T - SQL
DDL
(Data Definition Language)
DML
(Data Manipulation Language)
DCL
(Data Control Language)
Sub-languages of T-SQL
SELECT commands
Note that the resultant calculated column “Price In VND” is not a new
column in the “Products” table; it is for display only.
Duplication Eliminating with
SELECT distinct
Selection in SQL (Restricting data)
If you use the ORDER BY clause, it must be the last clause of the SQL
statement.
ORDER BY clause: Specifies one or many column on which to sort.
A sort column can be specified as a name or column alias, 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.
The results are first sorted on the first column; then the tuples having the same value on
the first column will be sorted on the second column, and so on.
Example: Ordering the output