The SELECT statement is primarily used to retrieve zero or more rows from one or more tables in a database. In MySQL, SELECT is the most commonly used DML (Data Manipulation Language) command. In specifying a SELECT query, the user specifies a description of the desired result set. It is built with optional clauses that specify how and what data to retrieve. The general command syntax is shown below;
SELECT [<clause options>] <column list> [FROM] <table> [<clause options>];
Basic SELECT statement example using world database (and the result data):
mysql> SELECT Name FROM Country;
+-------------------------------------------------+
| Name |
+-------------------------------------------------+
| Afghanistan |
| Netherlands |
| Netherlands Antilles |
| Albania |
...
| French Southern Territories |
| Unites States Minor Outlying Islands |
+-------------------------------------------------+
239 rows in set (#.## sec)
The above example shows a typical query, which retrieves all the rows in a given column, from a specific table. Multiple columns can be listed in a query, as well.
SELECT can also be used to complete arithmetic operations, like this simple addition calculation;
mysql> SELECT 1+2;
+-----+
| 1+2 |
+-----+
| 3 |
+-----+
1 row in set (#.## sec)
Comments
Post a Comment