SQL Select table example – Learn how to retrieve data from a table in MySQL database with example and important points.
Select statement used to retrieve records from one or more database tables.The result is stored in the result table called result set.
SQL syntax to retrieve the data from multiple columns from tables.
SELECT [hint][DISTINCT] [select_list] FROM [table_list] [WHERE conditions] [GROUP BY group_by_list] [HAVING search_conditions] [ORDER BY order_list [ASC DESC] ] [FOR UPDATE for_update_options]
SQL Select – Retrieve data from Multiple Columns
SQL query to retrieve all the columns from the table.
Select * from books;
in the above example * is a wild card which means “all columns”;
SQL Select – Retrieve data from Single Column
SQL query to retrieve the data from single column from the table. We will retrieve data from TITLE column from a BOOKS table.
Example query: select TITLE from BOOKS;
- Using select statement we can retrieve data with multiple columns by specifying column names.
- From key word used to indicate from which database tables the data is taken.
- Where key word used to identify which rows to be retrieved.
- Group by groups rows to apply aggregate functions to each group.
- Having is applied on the results of group by and can use agree gate functions.
- Order by specifies an order in which to return the rows.