본문 바로가기
MySQL

SQL 문법/실행 순서

by 찬찬2 2020. 12. 29.

문법 순서

SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY

 

실행 순서

FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY

 

- AND | OR | NOT

 

- Combining : "( )"

 

- Declare Conditions : Column = 'value'

* when using "NOT", it has to be in front of Condition statement!!

- DESC, ASC : descending, ascending

* DESC, ASC must be at the end of "ORDER BY + column".

* DESC, ASC can be used in several Columns. (ORDER BY column ASC, column DESC)

- IS NULL, IS NOT NULL : 

* IS NULL, IS NOT NULL comes after "WEHRE clause"

- AS :  used to give a table, or a column in a table, a temporary name.

* [example] SELECT CustomerName AS Customer, ContactName AS [Contact Person]

It requires double quotation marks or square brackets if the alias name contains spaces:

 

* [example] SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address

The following SQL statement creates an alias named "Address" that combine four columns (Address, PostalCode, City and Country):

 

 

댓글