What is the full syntax of a SELECT query?

The SELECT command is a SQL (Structured Query Language) statement used to retrieve data from one or more tables in a database.

SELECT command is one of the different SQL statements used to interact with a database system. SELECT command is used to query and retrieve data from a relational table, optionally combining more than one tables as required.

With SELECT you can join multiple tables for data, project with customization, filter with any condition, sort and group the result set.

The full syntax of a SELECT query with all the possible CLAUSES is:


SELECT column_list | *
FROM table_name 
[ JOIN table_name1 ON join_condition ]
[ JOIN table_name2 ON join_condition .. ]
[ WHERE query_condition ]
[ GROUP BY group_by_column_list expression ]
[ HAVING query_condition ]
[ ORDER BY column_list [ ASC | DESC ]
 

Let us examine each of this segment individually –

  1. column_list is where the list of desired columns is mentioned.
  2. JOIN conditions to link results from more than one tables which are related by common column(s) or key(s)
  3. WHERE condition to specify the filtering condition on the result dataset
  4. GROUP BY to aggregate the result data based one or more columns
  5. HAVING is a secondary condition to apply on the data that is grouped using the GROUP BY clause
  6. ORDER BY is to sort the final dataset based on one or more columns.

Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *