What is a “request”? What do they mean by querying the database? What are the queries that are sent to the database for?
By request is meant the supply of certain conditions, according to which the database will give an answer and provide information of interest. Those. it sends certain conditions / data, according to which the necessary information is selected and transmitted to the client / or entered into the database. The answer to the question "what is the object intended for, the request", you will certainly learn from this article.
Why do we need database queries?
It is necessary to answer not only the question of what the request is, but also the question of what the requests are for. They are necessary to get the information that is stored in the database. Simply put, queries in the database are designed to obtain the information needed in individual cases. Their purpose can be very different: it may be necessary for identification as a bank customer on a third-party site, or for identification as an employee of the internal corporate network, or for obtaining information about the profile status on the game’s website.
What are the components of the request?
We continue to answer the question: what are the requests for? SQL is used to write queries. There must be only two components: SELECT and FROM. But besides them, a number of other commands can be used and are used, which add new requirements to the selection of data and their sorting with display. These queries in the database are designed to receive the most necessary information by the computer: what you need to find and where it is something you need to look for. The most popular component after the required parts is
Where. Where is used to set specific conditions for data selection. So, here you can specify an identification number, date of birth or other information that is unique and by which a person can be identified.
Query building
Any request has a strict hierarchy of construction, which cannot be violated. For an error may occur. The construction will be told on the basis of a simple query with three components. First come SELECT, FROM, and Where. Operators can be typed in both capital and small letters, this does not affect the execution. But according to the rules of good tone, all operators are written with a capital letter, and the desired conditions, table names, etc. with a small one. And so it’s easier to navigate while viewing the code. Returning to the code, we should separately tell what is responsible for.
Building a query, as a rule, does not differ when working in different development environments. So, the question is before you: “what are the requests in access for” or in another development environment, and you can be sure that the answers given in this article will suit all of them.
Request Master Data
The main component parts, as mentioned earlier, are only two:
- SELECT [what you need 1, what you need 2, what you need 3] - is used to indicate what information is needed. It will be transferred from the database to the program with which the user is working.
- FROM [the table from which the data is taken] - indicate the required data a little, you also need to indicate where they should be taken from. The database itself does not store data, but tables in which the data itself is already. Different tables may have the same data columns to avoid this, and use an indication of where it comes from.
Additional request data and group operations
To improve the search result and
provide information on already received information, additional commands are used:
- Where [search terms] - is used to sort the necessary information regarding certain selection conditions.
- LIMIT [number] - used to limit the number of rows that will be taken from the table.
- GROUP BY [query parameter] - used to group the received information from the database. But the grouping may not be provided with any information, but only proportionate and having the same type. You can find out more in detail by finding a separate article on GROUP BY. Group operations in requests are intended to improve the appearance of the information provided and its greater readability.
- UNION [query] is used to place a separate subquery in a query. When you receive a fairly significant amount of information, you may need this option.
- LIKE “” is used to check whether the mask in the request matches the size of certain data. So, with its help, a person can be sought whose salary is measured in six-digit numbers.
Example
By itself, understanding what is written is problematic, without specifying an appropriate example. But even one example cannot explain everything, and you have to look for a lot of information until you can understand all the possibilities that SQL developers provide:
SELECT Name, ProductNumber, ListPrice AS Price
FROM Production.Product
WHERE ProductLine = 'R'
We parse the code I proposed above. First comes the selection of the necessary data: name, product number and page price list. Moreover, the price list is displayed under a slightly different name - simply “price”. Data is taken from the database “Products” from the table “Product”. In general, specifying a database is not necessary if you are working with only one, to which you are actually sending a request. But if there are several databases, be sure to indicate, given that the computer simply won’t understand who you are contacting or will completely ignore your request and give an error. The third line indicates that not all information is displayed, but only that which goes in the P product line. So the short article ended, after reading which you now understand what the queries are for.