0% found this document useful (0 votes)
18 views5 pages

Select Statemenmts

Complete about select statements

Uploaded by

Shabber Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Select Statemenmts

Complete about select statements

Uploaded by

Shabber Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Section 2: Querying Data

 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:

 First, we should specify a list of comma-separated columns from the table in


the SELECT clause.
 Then, we should specify the table name in the FROM clause.

 When evaluating the SELECT statement, the database system evaluates


the FROM clause first and then the SELECT clause. It’s like from a table, select data
from these columns.
 The semicolon (;) is not part of a query. The database server uses it to separate two
SQL statements

 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:

SELECT * FROM table_name;

 SQL is case-insensitive. the SELECT and select keywords have the


same meaning.

 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 |

SQL SELECT – selecting data from all columns

SELECT * FROM employees;

| employee_id | first_name | last_name | email | phone_number | hire_date | job_id | salary


| manager_id | department_id |
+-------------+-------------+-------------+-----------------------------------+--------------+------------+--------+----------
+------------+---------------+
| 100 | Steven | King | [email protected] | 515.123.4567 | 1987-06-17 | 4|
24000.00 | NULL | 9|
| 101 | Neena | Kochhar | [email protected] | 515.123.4568 | 1989-09-21 | 5|
17000.00 | 100 | 9|
| 102 | Lex | De Haan | lex.de [email protected] | 515.123.4569 | 1993-01-13 | 5|
17000.00 | 100 | 9|
| 103 | Alexander | Hunold | [email protected] | 590.423.4567 | 1990-01-03 | 9|
9000.00 | 102 | 6|
| 104 | Bruce | Ernst | [email protected] | 590.423.4568 | 1991-05-21 | 9|
6000.00 | 103 | 6|
| 105 | David | Austin | [email protected] | 590.423.4569 | 1997-06-25 | 9|
4800.00 | 103 | 6|
| 106 | Valli | Pataballa | [email protected] | 590.423.4560 | 1998-02-05 | 9|
4800.00 | 103 | 6|
| 107 | Diana | Lorentz | [email protected] | 590.423.5567 | 1999-02-07 | 9|
4200.00 | 103 | 6|
| 108 | Nancy | Greenberg | [email protected] | 515.124.4569 | 1994-08-7 | 7 |
12000.00 | 101 | 10 |

| 105 | David | Austin | [email protected] | 590.423.4569 | 1997-06-25 | 9


| 4800.00 | 103 | 6|
| 106 | Valli | Pataballa | [email protected] | 590.423.4560 | 1998-02-05 | 9|
4800.00 | 103 | 6|
| 107 | Diana | Lorentz | [email protected] | 590.423.5567 | 1999-02-07 | 9
| 4200.00 | 103 | 6|
| 108 | Nancy | Greenberg | [email protected] | 515.124.4569 | 1994-08-17 |
7 | 12000.00 | 101 | 10 |

SQL SELECT – performing a simple calculation

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
|

...

The expression salary * 1.05 adds 5% to the salary of every employee

You might also like