SQL SELECT TABLE Statement
Select statement is used to retrieve data from the databases. We will get the resulting data in the form of query format that may very from one RDBMS product to other product.
SQL SELECT - Syntax
SELECT(column-name1,column-name2,...column-nameN) FROM Table-name; (Or) SELECT(column-name1,column-name2,...column-nameN) FROM Table-name [WHERE [condition]];SELECT statement consists of six classes such as SELECT, FROM, WHERE, HAVING, GROUP BY, ORDER BY. The SELECT and FROM clauses must be required to form SELECT statement, and other clauses are optional.
The Select statement begins with the SELECT clause and followed by the list of select items which are going to be retrieved from the database. The select items can be column name or constant or SQL expressions that are separated by commas. After this select items, FROM clause is specified that identifies the source table or view where the specified data to be reside.
SELECT Statement Example
Consider the [student] table:
+--------+---------+------+-----------+ | RollNo | Name | Age | City | +--------+---------+------+-----------+ | 1 | Aruna | 18 | Chennai | | 2 | Varun | 19 | Bangalore | | 3 | Ara | 19 | Kerala | | 4 | Markdin | 18 | Mumbai | | 5 | Kannan | 20 | Kerala | | 6 | Kanika | 18 | Chennai | +--------+---------+------+-----------+
Following is the query to select the column of [Name] and [City] from the above [student] table.
mysql> SELECT Name, City FROM student; +---------+-----------+ | Name | City | +---------+-----------+ | Aruna | Chennai | | Varun | Bangalore | | Ara | Kerala | | Markdin | Mumbai | | Kannan | Kerala | | Kanika | Chennai | +---------+-----------+ 6 rows in set (0.10 sec)
SELECT * statement
This SQL statement is used to select all records from the table in the database.
Syntax
SELECT * FROM table-name;
Example
Below is the example SELECT statement to select all recors from the [student] table.
mysql> SELECT * FROM student; +--------+---------+------+-----------+ | RollNo | Name | Age | City | +--------+---------+------+-----------+ | 1 | Aruna | 18 | Chennai | | 2 | Varun | 19 | Bangalore | | 3 | Ara | 19 | Kerala | | 4 | Markdin | 18 | Mumbai | | 5 | Kannan | 20 | Kerala | | 6 | Kanika | 18 | Chennai | +--------+---------+------+-----------+ 6 rows in set (0.42 sec)