Definition

query

What is a query?

A query is a question or a request for information expressed in a formal manner. In computer science, a query is essentially the same thing, the only difference is the answer or retrieved information comes from a database.

What is a database query?

A database query is either an action query or a select query. A select query is one that retrieves data from a database. An action query asks for additional operations on data, such as insertion, updating, deleting or other forms of data manipulation.

This doesn't mean that users just type in random requests. For a database to understand demands, it must receive a query based on the predefined code. That code is a query language.

What is a query in SQL?

Query languages are used to make queries in a database, and Microsoft Structured Query Language (SQL) is the standard. Note: SQL and MySQL are not the same, as the latter is a software extension that uses SQL. Other language extensions of the language include Oracle SQL and NuoDB.

Although Microsoft's SQL is the most popular language, there are many other types of databases and languages. These include NoSQL databases and graph databases, Cassandra Query Language (CQL), Data Mining Extensions (DMX), Neo4j Cypher and XQuery.

SQL vs. NoSQL

Modern databases are chosen based on data structure and on whether a database is relational (SQL) or non-relational (NoSQL). While both are viable options, some key differences set them apart. For example, NoSQL databases are horizontally scalable (they scale out), while SQL databases are vertically scalable (scaling up). SQL databases also have a predefined schema and use a structured query language. By contrast, NoSQL databases leverage dynamic schemas for unstructured data and are document-based with graphs, key-values or wide-column stores.

How do queries work?

Queries can accomplish a few different tasks. Primarily, queries are used to find specific data by filtering explicit criteria. Queries also help automate data management tasks, summarize data and engage in calculations.

Other examples of queries include append, crosstab, delete, make a table, parameter, totals and updates.

Meanwhile, a query parameter runs variations of a particular query, prompting users to insert a field value and then use that value to create a criterion. Totals queries, on the other hand, allow users to group and summarize data.

A SQL query example
An example of SQL query.

In a relational database, which contains records or rows of information, the SQL SELECT statement query allows users to choose data and return it from a database to an application. The resulting query is stored in a result table, which is called a result-set. Users can break down the SELECT statement into other categories like FROM, WHERE and ORDER BY. The SQL SELECT query can also group and aggregate data to analyze or summarize.

At its most basic, a query is like ordering a cup of coffee at a cafe. You walk up to the barista and make your request by asking, "May I have a cup of coffee?" The barista understands your request and gives you a cup of coffee. Queries work in the same way.

A query gives meaning to the lines of code used in every query language. As such, both the user and the database exchange information as they both "speak" the same language. Querying by language is not the only way to request information from a database, though. Other popular examples include users performing a query by example or by using available parameters.

What is query folding?

For data sources like relational and non-relational databases like Active Directory, OData or Exchange, a mashup engine "translates" from M Language -- the data transformation language of Power Query (a data mashup and transformation tool) -- to a language understood by the underlying data source. Most often, that language would be SQL.

When complex calculations and transformations are pushed directly to the source, Power Query uses robust relational database engines developed to handle large volumes of data efficiently.

Query folding describes Power Query's ability to generate a single query statement to retrieve and transform source data. The Power Query mashup engine attempts to accomplish query folding to enhance efficiency whenever possible.

Users can also perform hundreds of different data transformations using Power BI, Microsoft's business intelligence platform, which builds in Power Query to engage in query folding. Power BI includes tools that aggregate, analyze, visualize and share data.

What is query containment?

Query containment occurs when one query is contained in another, independent of stored data values. For example, this could be a subset of answers to the first query in a database.

Web search query

A web search query describes what users search for when they type a question or a word in search engines such as Bing, Google or Yahoo. Search engine queries provide information that is much different from SQL queries, as they don't require positional parameters or keywords. A search engine query is essentially a request for information on a specific topic.

Search engines uses an algorithm to search and find the most accurate results to requests. They sort these based on significance and according to the particular search engine -- details of which are not revealed publicly.

Types of search queries include navigational, informational and transactional. Navigational searches are intended to find a particular website, such as ESPN.com; informational searches are designed to cover a broad topic, such a comparison between a new iPhone and Android device; and transactional searches seek to complete a transaction, such as the purchase of a new sweater on Amazon.com.

Other kinds of queries

Some queries have nothing to do with the above; among these are querySelector() in JavaScript and query errors in Facebook.

JavaScript's querySelector() helps users find the first element that matches a particular CSS selector. To return all matching elements, developers also use the querySelectorAll() method. Whenever the selector isn't valid, the process raises a SyntaxError exception. If there are no matches, the querySelector() returns null.

Query errors occur on Facebook for a number of reasons. Whenever this happens, users get a message like "Error performing query." This is usually fixed by rebooting the device, refreshing the page, logging out and logging back in or by clearing the cache and cookies.

This was last updated in May 2021

Continue Reading About query

Dig Deeper on Database management

SearchBusinessAnalytics
SearchAWS
SearchContentManagement
SearchOracle
SearchSAP
SearchSQLServer
Close