Home > Database > Mysql Tutorial > body text

What is the meaning of 'SELECT' statement in MySQL and how to use it?

PHPz
Release: 2023-09-09 11:57:13
forward
1036 people have browsed it

What is the meaning of SELECT statement in MySQL and how to use it?

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.

Syntax

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]
Copy after login

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.

  • < li>

    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.

Example

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 = &lsquo;Ram&rsquo;;

+------+--------+
| 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template