MySQL select from select: the sampling operator

MySQL, like any other relational database management system, has a select SELECT in its structure. This is not surprising, because databases store information in themselves primarily in order to extract it when necessary. select from SELECT позволяет делать это множеством различных способов, предоставляя большой набор инструментов. The MySQL select from SELECT statement allows you to do this in a variety of ways, by providing a large set of tools.

Installing MySQL

MySQL is implemented for both Windows and Linux. To install MySQL Ubuntu, it is enough to execute two commands in the terminal of this OS:

- sudo apt-get install mysql-server.

- sudo apt-get install mysql-client.

For MySQL Windows, it's enough to download the corresponding installation packages from the official "DBMS" site and run them.

The general structure of the SELECT statement

The complete structure in MySQL select from SELECT statement looks like this:

1. SELECT - the names of the columns (fields).

2. FROM - table names.

3. WHERE is the condition for sampling.

Note that although the syntax of the SQL language is not case sensitive, it is a good idea to write operators and reserved keywords (FROM, WHERE, etc.) in capital letters, and the names of the tables and their columns are small. SELECT приведен на рисунке ниже. The simplest example of using the MySQL select from SELECT operator is shown in the figure below.

An asterisk after the word SELECT is an analog of the ALL keyword and means that all columns should be selected from the specified table. If you are only interested in some of the fields in the table, you must specify them in the appropriate place, separated by commas. The same applies to the names of the tables - if there are several of them, enter them all separated by commas.

Using the WHERE clause

Obviously, you could not help noticing that in the previous example, the WHERE keyword is missing - this is because in this case we do not need it. This operator is not mandatory, and there are many such optional operators in SELECT, but they are a little later. If you add after the name of the WHERE table and any condition, for example type = 'dog', then in the resultant selection you get only one row with a pet named Edison. The figure below shows an example. Do not pay attention to the ORDER BY clause, it does not play any role here, and it will be discussed a little later.

It is worth noting that after the WHERE you can also write several conditions, but not through a comma. For this purpose, you must use keywords such as AND or OR. It all depends on how your conditions should be respected. If you are interested in a result that satisfies all the conditions you specify, then there must be an AND between them, and if the result should satisfy at least one of them, then use OR.

ORDER BY clause

We mentioned that in addition to WHERE there are a lot of other keywords in the SELECT statement, with which you can manipulate the resultant selection as required in a particular situation. One such "key" is ORDER BY. It allows you to sort the results of a sample by a specific field, either in ascending or descending order. To do this, you just need to specify the name of the column after it, according to the values of which you need to sort the data. It is important to observe several conditions: first, the name specified in the ORDER BY statement must be present in the SELECT itself; The second - ORDER BY must be placed at the very end of the request.

By default, sorting is performed in ascending order (ASC), but if you want to sort the result in descending order, write the DESC keyword after the field name instead of ASC.


We examined the basic, but not all, tools of the MySQL operator select from. SELECT, besides the above, has a lot of other features that allow you to extract data from the database flexibly and efficiently.

Similar articles





Trending Now






Copyright © 2018 Theme powered by WordPress.