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 –
- column_list is where the list of desired columns is mentioned.
- JOIN conditions to link results from more than one tables which are related by common column(s) or key(s)
- WHERE condition to specify the filtering condition on the result dataset
- GROUP BY to aggregate the result data based one or more columns
- HAVING is a secondary condition to apply on the data that is grouped using the GROUP BY clause
- ORDER BY is to sort the final dataset based on one or more columns.