SQL 1 (Basic)
SQL 1 (Basic)
SQL 1 (Basic)
kal@ittelkom.ac.id
Outline
SQL History Basic SQL Select Statement Arithmetic Operators Where Clause Sorting
SQL History
The first version of SQL was developed at IBM by Andrew Richardson, Donald C. Messerly and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL, was designed to manipulate and retrieve data stored in IBM's original relational database product, System R. IBM patented their version of SQL in 1985, while the SQL language was not formally standardized until 1986 by the American National Standards Institute (ANSI) as SQL-86.
SQL Statements
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. You can choose as few or as many columns of the table as you require. Selection: You can use the selection capability in SQL to choose the rows in a table that you want returned by a query. You can use various criteria to restrict the rows that you see. 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. You learn more about joins in a later lesson.
Selection
Table 1 Join
Table 1
Table 1
Table 2
Arithmetic Expressions
Create expressions with number and date data by using arithmetic operators.
Operator + Description Add Subtract
*
/
Multiply
Divide
Operator Precedence
* / +
_
Multiplication and division take priority over addition and subtraction. Operators of the same priority are evaluated from left to right. Parentheses are used to force prioritized evaluation and to clarify statements.
Operator Precedence
SELECT last_name, salary, 12*salary+100 FROM employees;
Using Parentheses
SELECT last_name, salary, 12*(salary+100) FROM employees;
Concatenation Operator
A concatenation operator: Concatenates columns or character strings to other columns Is represented by two vertical bars (||) Creates a resultant column that is a character expression
Duplicate Rows
The default display of queries is all rows, including duplicate rows.
SELECT department_id FROM employees;
Comparison Conditions
Operator
= > >= < <= <>
Meaning
Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
BETWEEN ...AND...
IN(set) LIKE IS NULL
Lower limit
Upper limit
You can use the ESCAPE identifier to search for the actual % and _ symbols.
SELECT employee_id, last_name, job_id FROM employees WHERE job_id LIKE '%SA\_%' ESCAPE '\';
Logical Conditions
Operator Meaning
AND
OR
NOT
Rules of Precedence
Order Evaluated 1 2 3 4 5 6 7 8 Operator Arithmetic operators Concatenation operator Comparison conditions IS [NOT] NULL, LIKE, [NOT] IN [NOT] BETWEEN NOT logical condition AND logical condition OR logical condition
Rules of Precedence
SELECT FROM WHERE OR AND last_name, job_id, salary employees job_id = 'SA_REP' job_id = 'AD_PRES' salary > 15000;
ORDER BY Clause
Sort rows with the ORDER BY clause
ASC: ascending order, default DESC: descending order
Review
SQL History Basic SQL Select Statement Arithmetic Operators Where Clause Sorting
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: