SQL ( ) , - SQL. , , Select (SQL) - , .
, . SQL, Select () :
Select | , . . |
One, two, three… | |
From | , . . |
«» , , Select from .
:
Where , .
Group by, , Having.
Order by .
Select, , Cats :
Id | Breed | Name | Birthday | Color |
1 | | | 01.04.2017 | Grey |
2 | | | 16.03.2017 | White |
3 | | | 30.03.2017 | Black |
4 | | | 23.02.2017 | Grey |
5 | | | 08.01.2017 | Black |
, , , . , Select (SQL), .
, .
Select . , :
Select color, breed, name From Cats |
, , . , .
. Select (*) . :
- Cats, , .
, SQL Select . , , , .
Cats. , . (+), – (||) (&), Concat. , .
Select breed || ‘, ’ || color From cats |
:
Breed, Color |
, Grey |
, White |
, Black |
, Grey |
, Black |
Distinct – Select (SQL), .
, , . :
:
, . Distinct , :
Select distinct breed From Cats |
. , Select (SQL) .
Where. – , "" "". Select , True, "".
. , .
Select * From cats Where color = ‘Black’ |
:
3 | | | 30.03.2017 | Black |
5 | | | 08.01.2017 | Black |
, And, Or, Not.
Group by
Group by, Select (SQL), ( ), .
:
- Count – , .
- Sum – .
- Min – .
- Max – , .
- Avg – .
. , , . :
Select breed, count(*) From cats Group by breed |
:
, , . , , , , – .
, - , , , . Having. , Where, . . :
Select breed, count(*) From cats Group by breed Having count(*) <=10 |
« 10», , . Having. Having count(*) =1, , .
Order by – Select (SQL), .
, Order by – Select. Select, From, Where, Group by, Having.
:
1) , (ASC), (DESC).
2) Order by Select.
3) , , Select.
We hope that with the help of our article you have gained basic knowledge about using SQL queries and now you can easily select the necessary information from your DBMS.