{"id":13857,"date":"2021-08-26T07:34:31","date_gmt":"2021-08-26T07:34:31","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=13857"},"modified":"2025-12-02T15:30:07","modified_gmt":"2025-12-02T15:30:07","slug":"what-is-a-query","status":"publish","type":"post","link":"\/ca\/tutorials\/what-is-a-query","title":{"rendered":"What is a query?"},"content":{"rendered":"<p>A query is a <strong>request for information or an action from a database or search engine<\/strong>. In plain English, a query is simply a question. In a technical context, it&rsquo;s a specific command sent to a system to retrieve data or perform a task.<\/p><p>To communicate with a database, you must write these requests in a specific query language, such as Structured Query Language (SQL).<\/p><p>Understanding how queries function involves a few core concepts:<\/p><ul class=\"wp-block-list\">\n<li><strong>Mechanism<\/strong>. Queries operate on a simple request-process-output flow to retrieve information or perform actions.<\/li>\n\n\n\n<li><strong>Main types<\/strong>. These include <strong>Select<\/strong> queries to fetch data and <strong>Action<\/strong> queries (<strong>INSERT<\/strong>, <strong>UPDATE<\/strong>, <strong>DELETE<\/strong>) to modify it.<\/li>\n\n\n\n<li><strong>Query languages<\/strong>. The primary languages are SQL for relational databases and NoSQL for non-relational ones.<\/li>\n<\/ul><p>Though people also use <em>query<\/em> to mean a question entered into a search engine, the term most often refers to a <strong>request<\/strong> sent to a database.<\/p><p>For a visual explanation of what a query is, check out this video from Hostinger Academy.<\/p><figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"What Is a Query | Explained\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/NqjfQswuBug?start=211&amp;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure><p>\n  <div class=\"youtube-shortcode\">\n    <div class=\"row\">\n      <div class=\"col-7 col-sm-8 d-flex align-items-center\">\n        <img decoding=\"async\" class=\"channel-logo\" src=\"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/youtube-channels\/hostinger-academy.jpg\" alt=\"youtube channel logo\">\n        <div class=\"d-flex flex-column justify-content-between\">\n          <span class=\"slogan d-none d-sm-block\">Subscribe For more educational videos!<\/span>\n          <span class=\"channel-name\">Hostinger Academy<\/span>\n                    <\/div>\n      <\/div>\n      <div class=\"col-5 col-sm-4 d-flex align-items-center justify-content-end\">\n          <a class=\"subscribe-button\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" href=\"http:\/\/www.youtube.com\/channel\/UCbNIC-svDbtUOH2qsLnPQPg?sub_confirmation=1\">\n            <img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/icons\/youtube.svg\" alt=\"subscribe\">\n            <span>Subscribe<\/span>\n          <\/a>\n      <\/div>\n    <\/div>\n  <\/div>\n\n    \n\n\n\n<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/Web-Development-Glossary-for-Beginners.pdf\" target=\"_blank\" rel=\"noopener\">Download glossary for web beginners<\/a><\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-does-a-query-work\">How does a query work?<\/h2><p>A query works by <strong>sending a structured request in a specific language<\/strong>. A system, such as a database, processes the request and returns the needed information or performs an action.<\/p><p>Think of it like ordering at a coffee shop. When you ask for an Americano, you are making a request (a query). The barista understands your language, makes the coffee (processes your request), and gives you your drink (the output).<\/p><p>A database query works the same way: As long as you and the database &ldquo;speak&rdquo; the same language, you can request information, and the system provides it.<\/p><p>This process follows a simple flow:<\/p><ul class=\"wp-block-list\">\n<li><strong>Request<\/strong>. You write a command in a query language to ask for specific data.<\/li>\n\n\n\n<li><strong>Process<\/strong>. The <a href=\"\/ca\/tutorials\/dbms\">database management system (DBMS) <\/a>interprets your command.<\/li>\n\n\n\n<li><strong>Output<\/strong>. The system retrieves the data or performs the action and returns a response.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-what-are-the-different-types-of-queries\">What are the different types of queries?<\/h2><p>The main types of database queries are <strong>Select queries<\/strong>, which retrieve data, and<strong> Action queries<\/strong>, which modify data. You can also combine these operations to perform more complex tasks.<\/p><p>Here are the most common types and the SQL commands that define them:<\/p><ul class=\"wp-block-list\">\n<li><strong>Select query<\/strong>. The most common type of query. It fetches data from one or more tables in a database without changing the data itself.\n<ul class=\"wp-block-list\">\n<li>Example: Use the <strong>SELECT<\/strong> command to get everyone&rsquo;s names and occupations in a <strong>Participant<\/strong> table.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Action queries<\/strong>. These queries manipulate data, such as creating, changing, or deleting records.\n<ul class=\"wp-block-list\">\n<li><strong>Insert query<\/strong>. Adds new records or rows to a table using the <strong>INSERT INTO<\/strong> command.<\/li>\n\n\n\n<li><strong>Update query<\/strong>. Modifies existing records in a table with the <strong>UPDATE<\/strong> command and specific criteria.<\/li>\n\n\n\n<li><strong>Delete query<\/strong>. Removes one or more records from a table with the <strong>DELETE<\/strong> command, permanently erasing the data.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Combined query<\/strong>. This query uses a <strong>SELECT<\/strong> statement inside an Action query to identify which records to modify. Developers often achieve this with a subquery in the <strong>WHERE<\/strong> clause.\n<ul class=\"wp-block-list\">\n<li>Example: Use <strong>UPDATE<\/strong> to change the status of all employees in a <strong>Sales<\/strong> department, where the department ID is first found using a <strong>SELECT<\/strong> subquery.<\/li>\n<\/ul>\n<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UPDATE Employees  \nSET Status = 'Inactive'  \nWHERE DepartmentID IN (SELECT DepartmentID FROM Departments WHERE DepartmentName = 'Sales');<\/pre><h2 class=\"wp-block-heading\" id=\"h-query-languages\">Query languages<\/h2><p>To write a query, you need a query language. While several exist, the most common follow either <strong>SQL<\/strong> or <strong>NoSQL<\/strong> principles.<\/p><p>SQL is the <strong>standard language for relational databases<\/strong>. These databases store data in tables with rows and columns.<\/p><p>It&rsquo;s important to note the difference between SQL and MySQL: <strong>SQL is the query language, while MySQL is a popular database management system that uses SQL<\/strong>.<\/p><p>NoSQL (Not Only SQL) refers to <strong>languages designed for non-relational databases<\/strong>. These databases handle data more flexibly and store unstructured formats, such as documents or key-value pairs.<\/p><p>A NoSQL database works well when your data doesn&rsquo;t fit neatly into tables.<\/p><p>Other specialized query languages include ArangoDB Query Language (AQL), Datalog, and Data Mining Extensions (DMX).<\/p><h2 class=\"wp-block-heading\" id=\"h-query-examples\">Query examples<\/h2><p>Let&rsquo;s look at some practical SQL query examples. Suppose you have a database table named <strong>Participant<\/strong> with the following data:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>ID<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Sex<\/strong><\/td><td><strong>Age<\/strong><\/td><td><strong>Occupation<\/strong><\/td><\/tr><tr><td>1<\/td><td>John<\/td><td>Male<\/td><td>17<\/td><td>Student<\/td><\/tr><tr><td>2<\/td><td>Peter<\/td><td>Male<\/td><td>26<\/td><td>Unemployed<\/td><\/tr><tr><td>3<\/td><td>Margareth<\/td><td>Female<\/td><td>34<\/td><td>Teacher<\/td><\/tr><tr><td>4<\/td><td>Lea<\/td><td>Female<\/td><td>34<\/td><td>Unemployed<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Selecting specific data<\/strong><\/p><p>To retrieve only the <strong>Name<\/strong> and <strong>Occupation<\/strong> columns from the <strong>Participant<\/strong> table, you would use a <strong>SELECT<\/strong> query.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT Name, Occupation FROM Participant;<\/pre><p>The result would be a new table with only the requested data:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Name<\/strong><\/td><td><strong>Occupation<\/strong><\/td><\/tr><tr><td>John<\/td><td>Student<\/td><\/tr><tr><td>Peter<\/td><td>Unemployed<\/td><\/tr><tr><td>Margareth<\/td><td>Teacher<\/td><\/tr><tr><td>Lea<\/td><td>Unemployed<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Deleting data<\/strong><\/p><p>To remove all participants whose occupation is <strong>Unemployed<\/strong>, you would use a <strong>DELETE<\/strong> query with a <strong>WHERE<\/strong> clause to specify the condition.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DELETE FROM Participant WHERE Occupation = 'Unemployed';<\/pre><p>This command removes the matching rows, leaving this result:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>ID<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Sex<\/strong><\/td><td><strong>Age<\/strong><\/td><td><strong>Occupation<\/strong><\/td><\/tr><tr><td>1<\/td><td>John<\/td><td>Male<\/td><td>17<\/td><td>Student<\/td><\/tr><tr><td>3<\/td><td>Margareth<\/td><td>Female<\/td><td>34<\/td><td>Teacher<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Inserting new data<\/strong><\/p><p>To add a new row to the table for a participant named <strong>Mario<\/strong>, you would use an <strong>INSERT INTO<\/strong> query.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INSERT INTO Participant (ID, Name, Sex, Age, Occupation)\nVALUES (5, 'Mario', 'Male', 29, 'Plumber');<\/pre><p>The <strong>Participant<\/strong> table would then include the new record.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>ID<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Sex<\/strong><\/td><td><strong>Age<\/strong><\/td><td><strong>Occupation<\/strong><\/td><\/tr><tr><td>5<\/td><td>Mario<\/td><td>Male<\/td><td>29<\/td><td>Plumber<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>Updating existing data<\/strong><\/p><p>To change Margareth&rsquo;s occupation to <strong>Headmaster<\/strong>, you can use an <strong>UPDATE<\/strong> query. The <strong>WHERE<\/strong> clause modifies only the correct record.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">UPDATE Participant SET Occupation = 'Headmaster' WHERE ID = 3;<\/pre><p>The query finds the row with <strong>ID = 3<\/strong> and updates the <strong>Occupation<\/strong> field.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>ID<\/strong><\/td><td><strong>Name<\/strong><\/td><td><strong>Sex<\/strong><\/td><td><strong>Age<\/strong><\/td><td><strong>Occupation<\/strong><\/td><\/tr><tr><td>3<\/td><td>Margareth<\/td><td>Female<\/td><td>34<\/td><td>Headmaster<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>A note on search engine queries<\/strong><\/p><p>It&rsquo;s also worth noting that the term &ldquo;query&rdquo; is used differently for search engines. A search engine query is simply<strong> the word or phrase you type into the search bar<\/strong>.<\/p><p>Unlike database queries, these don&rsquo;t require a special language &ndash; the search engine&rsquo;s algorithm processes your natural language to find relevant results.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-do-queries-work-in-databases\">How do queries work in databases?<\/h2><p>In a database, a query works <strong>when a DBMS interprets your command, scans the relevant tables for matching data, and returns the results<\/strong>. The DBMS acts as the software interface between the user and the database, handling all of these requests.<\/p><p>MySQL is one of the world&rsquo;s most popular open-source relational DBMS. To get a complete picture of the platform where these commands operate, we recommend you to <a href=\"\/ca\/tutorials\/what-is-mysql\">learn what MySQL is<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A query is a request for information or an action from a database or search engine. In plain English, a query is simply a question. In a technical context, it&rsquo;s a specific command sent to a system to retrieve data or perform a task. To communicate with a database, you must write these requests in [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/what-is-a-query\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":180,"featured_media":139700,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"What is a query? Database queries explained","rank_math_description":"Learn what a query is, how it works in databases and search engines, plus query types and languages like SQL with clear, simple examples.","rank_math_focus_keyword":"what is a query","footnotes":""},"categories":[22683,22685],"tags":[],"class_list":["post-13857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hosting","category-technical-aspects"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/what-is-a-query","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/o-que-e-query","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/que-es-consulta-base-de-datos","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/apa-itu-query","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/what-is-a-query","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/database-query","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/database-query","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-es-consulta-base-de-datos","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-es-consulta-base-de-datos","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/que-es-consulta-base-de-datos","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/o-que-e-query","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/what-is-a-query","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/what-is-a-query","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/what-is-a-query","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/what-is-a-query","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/13857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/180"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=13857"}],"version-history":[{"count":36,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/13857\/revisions"}],"predecessor-version":[{"id":138624,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/13857\/revisions\/138624"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media\/139700"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=13857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=13857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=13857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}