The SELECT command is used to get data from the MySQL database. You can use this command from the mysql> prompt as well as from any script such as PHP.
The following is the general syntax of the SELECT command to get data from a MySQL table- p>
SELECT field1, field2,...fieldN FROM table_name1, table_name2... [WHERE Clause] [OFFSET M ][LIMIT N]
Some points about the SELECT statement are as follows-
We can use one or more comma-separated tables to contain various conditions using the WHERE clause, but the WHERE clause is an optional part of the SELECT command.
We can get one or more fields in a single SELECT command.
We can specify an asterisk (*) in place of a field. In this case, SELECT returns all fields.
We can specify any condition using the WHERE clause.
We can use OFFSET to specify an offset from which SELECT will start returning records. By default, offsets start at zero.
We can use the LIMIT attribute to limit the number of returns.
mysql> Select * from Employee; +------+--------+ | Id | Name | +------+--------+ | 100 | Ram | | 200 | Gaurav | | 300 | Mohan | +------+--------+ 3 rows in set (0.00 sec) mysql> Select * from Employee Where Name = ‘Ram’; +------+--------+ | Id | Name | +------+--------+ | 100 | Ram | +------+--------+ 1 row in set (0.00 sec) mysql> Select Id from Employee; +-----+ | Id | +-----+ | 100 | | 200 | | 300 | +-----+ 3 rows in set (0.00 sec)
The above example shows some of the ways we can get records from a MySQL table using the SELECT statement.
The above is the detailed content of What is the meaning of 'SELECT' statement in MySQL and how to use it?. For more information, please follow other related articles on the PHP Chinese website!