Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct order of these clauses while writing a SQL query?

Tags:

sql-server

There are many clauses in SQL Server such as SELECT, WHERE, GROUP BY, ORDER BY, HAVING

What is the correct order of these clauses while writing a query?

like image 464
thevan Avatar asked Jan 11 '11 05:01

thevan


People also ask

What is the correct order of clauses in SQL?

Six Operations to Order: SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. By using examples, we will explain the execution order of the six most common operations or pieces in an SQL query.


1 Answers

http://msdn.microsoft.com/en-us/library/ms189499.aspx

[ WITH <common_table_expression>]

SELECT select_list [ INTO new_table ]

[ FROM table_source ] [ WHERE search_condition ]

[ GROUP BY group_by_expression ]

[ HAVING search_condition ]

[ ORDER BY order_expression [ ASC | DESC ] ]
like image 69
JeremyWeir Avatar answered Sep 25 '22 12:09

JeremyWeir