Download presentation
Presentation is loading. Please wait.
Published byDeborah Cunningham Modified over 9 years ago
2
After completing this lesson, you should be able to do the following: List the capabilities of MySQL SELECT statements Execute a basic SELECT statement
3
Selection Projection Table 1 Table 2 Table 1 Join
4
SELECT identifies what columns. FROM identifies which table. SELECT[DISTINCT] {*, column [alias],...} FROMtable; SELECT[DISTINCT] {*, column [alias],...} FROMtable;
5
MySQL statements are not case sensitive. MySQL statements can be on one or more lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability.
6
dept_nbr dept_name location --------- -------------- ------------- 10 Accounting New York 20 Research Dallas 30 Sales Chicago 40 Operations Boston MySQL>SELECT * ->FROM department;
7
dept_nbr location --------- ------------- 10 New York 20 Dallas 30 Chicago 40 Boston MySQL>SELECT dept_nbr, location ->FROM department;
8
Default justification Left: Date and character data Right: Numeric data Default display Case Matches Column Name at time of creation, i.e.: hire_date vs. HIRE_DATE
9
Create expressions on numeric data by using arithmetic operators. OperatorDescription +Add -Subtract *Multiply /Divide
10
MySQL>SELECT name, salary, salary+300 ->FROM employee; name salary salary+300 ---------- --------- --------- King 5000 5300 Blake 2850 3150 Clark 2450 2750 Jones 2975 3275 Martin 1250 1550 Allen 1600 1900... 14 rows selected.
11
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. ** //++__
12
MySQL>SELECT name, salary, 12*salary+100 ->FROM employee; name salary 12*salary+100 ---------- --------- ------------- King 5000 60100 Blake 2850 34300 Clark 2450 29500 Jones 2975 35800 Martin 1250 15100 Allen 1600 19300... 14 rows selected.
13
MySQL>SELECT name, salary, 12*(salary+100) ->FROM employee; name salary 12*(salary+100) ---------- --------- -------------- King 5000 61200 Blake 2850 35400 Clark 2450 30600 Jones 2975 36900 Martin 1250 16200... 14 rows selected.
14
A null is a value that is unavailable, unassigned, unknown, or inapplicable. A null is not the same as zero or a blank space. name job salary commission ---------- --------- --------- --------- King President 5000 Blake Manager 2850... Turner Salesman 1500 0... 14 rows selected. MySQL>SELECT name, job, salary, commission ->FROM employee;
15
Arithmetic expressions containing a null value evaluate to null. MySQL>select name, 12*salary+commission ->from employee ->WHERE name= ‘King’; name 12*salary+commission ------- -------------------- King
16
Renames a column heading Is useful with calculations Immediately follows column name; optional AS keyword between column name and alias Requires double quotation marks if it contains spaces or special characters or is case sensitive
17
MySQL>SELECT name as Employee_name, salary as Monthly_salary ->FROM employee; Employee_name Monthly_salary ------------- --------------... MySQL>SELECT name "Name", -> salary*12 "Annual Salary" ->FROM employee; Name Annual Salary ------------- -------------...
18
Concatenates columns or character strings to other columns Is represented by two vertical bars (||) Creates a resultant column that is a character expression
19
MySQL>SELECT name||job AS "Employees" ->FROM employee; Employees ------------------- KingPresident BlakeManager ClarkManager JonesManager MartinSalesman AllenSalesman... 14 rows selected.
20
A literal is a character, a number, or a date included in the SELECT list. Date and character literal values must be enclosed within single quotation marks. Each character string is output once for each row returned. CONCAT() function may also be used. Discussed with other Single Row Functions
21
Employee Details ------------------------- King is a President Blake is a Manager Clark is a Manager Jones is a Manager Martin is a Salesman... 14 rows selected. Employee Details ------------------------- King is a President Blake is a Manager Clark is a Manager Jones is a Manager Martin is a Salesman... 14 rows selected. MySQL>SELECT name||' is a '||job -> AS "Employee Details" ->FROM employee;
22
The default display of queries is all rows, including duplicate rows. MySQL>SELECT dept_nbr ->FROM employee; MySQL>SELECT dept_nbr ->FROM employee; dept_nbr --------- 10 30 10 20... 14 rows selected.
23
MySQL>SELECT DISTINCT dept_nbr ->FROM employee; dept_nbr --------- 10 20 30 Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.