Select Statemenmts
Select Statemenmts
SELECT Statement – how to query data from a single table by using SELECT
statement
The SQL SELECT statement selects data from one or more tables.
The syntax of the SELECT statement that selects data from a single table
SELECT
select_list
FROM
table_name;
In this syntax:
If you want to query data from all the columns of the table, you
can use the asterisk (*) operator instead if specifying all the
column names:
we will use the uppercase letters for the SQL keywords, such
as SELECT and lowercase letters for the identifiers such as table
and column names. This make SQL statements more readable
We consider employees as a a name of DATABASEand employee_id as TABLE name
SQL SELECT – selecting data from specific columns
select data from the employee id, first name, last name, and hire date of all
rows in the employees table
SELECT
employee_id,
first_name,
last_name,
hire_date
FROM
employees;
| employee_id | first_name | last_name\ hire_date
+-------------+-------------+-------------+------------+
100 | Steven | King | 1987-06-17 |
101 | Neena | Kochhar | 1989-09-21 |
102 | Lex | De Haan | 1993-01-13 |
103 | Alexander | Hunold | 1990-01-03
104 | Bruce | Ernst | 1991-05-21 |
105 | David | Austin | 1997-06-25 |
106 | Valli | Pataballa | 1998-02-05 |
107 | Diana | Lorentz | 1999-02-07 |
108 | Nancy | Greenberg | 1994-08-17 |
109 | Daniel | Faviet | 1994-08-16 |
110 | John | Chen | 1997-09-28 |
SELECT
first_name,
last_name,
salary,
salary *
1.05
FROM
employees;
+-------------+-------------+----------+---------------+
| first_name | last_name | salary | salary * 1.05 |
+-------------+-------------+----------+---------------+
| Steven | King | 24000.00 | 25200.0000 |
| Neena | Kochhar | 17000.00 | 17850.0000
|
| Lex | De Haan | 17000.00 | 17850.0000 |
| Alexander | Hunold | 9000.00 | 9450.0000 |
| Bruce | Ernst | 6000.00 | 6300.0000 |
| David | Austin | 4800.00 | 5040.0000 |
| Valli | Pataballa | 4800.00 | 5040.0000 |
| Diana | Lorentz | 4200.00 | 4410.0000 |
| Nancy | Greenberg | 12000.00 | 12600.0000
|
...