You are on page 1of 16

Query in Database

University Of Grarmian
IT Department
Stage 2

Prepared by: Ahmad Taha Aziz


Supervisor: MR.soran Pasha
INTRODUCTION

In standard English, a query means a request for information. In


computer programming, it refers to the same thing, except the
information is retrieved from a database.
However, writing a query requires a set of pre-defined code to make
the database understand the instruction. This concept is also known
as the query language.
While the standard language for database management
is Structured Query Language (SQL), other query languages to
make database communication easy include AQL, Datalog,
and DMX.
HOW DOES QUERY WORK?

Let’s say that you want to order an Americano at a coffee shop. You
make a request by saying, “Can I have an Americano?”. The barista
will understand the meaning of your request and give you the
ordered item.
A query works the same way – it adds meaning to the code,
allowing the system to understand and execute actions accordingly.
Be it SQL or any other query language, both the user and the
database can exchange information as long as they use the same
language.
Meanwhile, a well-designed database stores data in multiple tables.
They consist of columns that hold the data’s attributes, along with
rows or records of information. A query then helps retrieve data
from different tables, arrange them, and display them according to
the commands.
A query can either be a select, an action, or a combination of both.
Select queries can retrieve information from data sources, and
action queries work for data manipulation, for example, to add,
change or delete data.
Advanced users can also use query commands to perform various
programming tasks, from creating MySQL users  and granting
permissions to changing WordPress URLs  in MySQL databases.
Below are some of the most common query commands along with
their functions:
 SELECT – fetch data from the database. It’s one of the most
popular commands, as every request begins with a select
query.

 AND – combine data from one or more tables.

 CREATE TABLE – build different tables and specify the name


of each column within.

 ORDER BY – sort data results either numerically or


alphabetically.

 SUM – summarize data from a specific column.

 UPDATE – modify existing rows in a table.

 INSERT – add new data or rows to an existing table.

 WHERE – filter data and get its value based on a set


condition.

For more variations, combine some of the commands above. For


example, pair the SELECT query with other commands
like AND or SUM to aggregate data or combine results.
Besides using query language to request information from a
database, other methods include:

 Using available parameters. By default, the database


software has lists of parameters that users can define as they
need. These parameters deal with exchanging information
between user-defined functions (UDF)  and stored
procedures (SP).
 Query by example (QBE). Relational databases use a
graphical query language. The system will show a code
template in which you can write and specify the fields and
values of your data. So instead of writing complete SQL
statements, a user can fill the blank areas.

 Installing database plugins. An ideal solution for beginners –


the plugins let users perform various database tasks, including
queries, with only a few clicks. Additionally, some plugins
come with optimization features to ensure the best
performance.

In addition to databases, search engines can also query and


retrieve information. However, the term query in these two
technologies differs.
Web search query refers to keywords that users type in the search
engine, while database query is a particular action to make a
request for information.
Now that you understand the basic fundamentals of queries, let’s
study several standard terms you might come across when
querying a database:

 Query string – a portion of URL to pass requests from the


web to the database.

 Query parameters – elements attached to the end of an URL


to specify a particular query on the database.
 Query folding – refers to a process where the Power
Query is enabled to transform complex calculations for query
optimization.

 Query containment – happens when one query is contained


in another, if it is independent of the stored data values.

QUERY LANGUAGES
As mentioned before, choosing the database and its language is
crucial when working with queries. In addition to SQL, there is
another type of database called NoSQL (Not Only Structured Query
Language). The main difference between the two is the data
structure.
SQL databases are relational and use predefined schemas that
require you to specify your data structure. On the other hand,
NoSQL databases are non-relational and have dynamic schemas
for unstructured data.
Regardless, both SQL and NoSQL provide applicable options. An
SQL database is a great choice for an ACID-compliant  data
structure. Conversely, if you have unstructured documents, key-
values, or graphs, a NoSQL database might be an ideal choice.
QUERY EXAMPLES

Before we delve into the examples, below are the main benefits of
using a query:

 Review data from multiple tables simultaneously.

 Filter records containing only certain fields and of certain


criteria.

 Automate data management tasks and perform calculations.

Now, let’s suppose you have collected some data from a survey.
Below is a snippet of your data. Note that for this example, we will
use an SQL database.
Data source: Participant (Table Name)

ID Name Sex Age Occupation

1 John Male 17 Student

2 Peter Male 26 Unemployed

3 Margareth Female 34 Teacher

4 Lea Female 34 Unemployed


Glossary

Dec 07, 2022


Nabilla R.
5min Read

WHAT IS A QUERY?
DATABASE QUERY
EXPLAINED

In standard English, a query means a request for information. In


computer programming, it refers to the same thing, except the
information is retrieved from a database.
However, writing a query requires a set of pre-defined code to make
the database understand the instruction. This concept is also known
as the query language.
While the standard language for database management
is Structured Query Language (SQL), other query languages to
make database communication easy include AQL, Datalog,
and DMX.

Important! Note that SQL is different from MySQL  – the former is


the query language, while the latter is the software that uses the
language.

This article will explain how a query works, examples of queries,


and cover the steps of writing them in the database.
Download Glossary For Web Beginners
o What Is a Query?
o How Does Query Work?
o Query Languages
o Query Examples

WHAT IS A QUERY?
A database query is a request for data from a database. The
request should come in a database table or a combination of tables
using a code known as the query language. This way, the system
can understand and process the query accordingly.
HOW DOES QUERY WORK?
Let’s say that you want to order an Americano at a coffee shop. You
make a request by saying, “Can I have an Americano?”. The barista
will understand the meaning of your request and give you the
ordered item.
A query works the same way – it adds meaning to the code,
allowing the system to understand and execute actions accordingly.
Be it SQL or any other query language, both the user and the
database can exchange information as long as they use the same
language.
Meanwhile, a well-designed database stores data in multiple tables.
They consist of columns that hold the data’s attributes, along with
rows or records of information. A query then helps retrieve data
from different tables, arrange them, and display them according to
the commands.
A query can either be a select, an action, or a combination of both.
Select queries can retrieve information from data sources, and
action queries work for data manipulation, for example, to add,
change or delete data.
Advanced users can also use query commands to perform various
programming tasks, from creating MySQL users  and granting
permissions to changing WordPress URLs  in MySQL databases.
Below are some of the most common query commands along with
their functions:
 SELECT – fetch data from the database. It’s one of the most
popular commands, as every request begins with a select
query.

 AND – combine data from one or more tables.

 CREATE TABLE – build different tables and specify the name


of each column within.

 ORDER BY – sort data results either numerically or


alphabetically.

 SUM – summarize data from a specific column.

 UPDATE – modify existing rows in a table.

 INSERT – add new data or rows to an existing table.

 WHERE – filter data and get its value based on a set


condition.

For more variations, combine some of the commands above. For


example, pair the SELECT query with other commands
like AND or SUM to aggregate data or combine results.
Besides using query language to request information from a
database, other methods include:

 Using available parameters. By default, the database


software has lists of parameters that users can define as they
need. These parameters deal with exchanging information
between user-defined functions (UDF)  and stored
procedures (SP).
 Query by example (QBE). Relational databases use a
graphical query language. The system will show a code
template in which you can write and specify the fields and
values of your data. So instead of writing complete SQL
statements, a user can fill the blank areas.

 Installing database plugins. An ideal solution for beginners –


the plugins let users perform various database tasks, including
queries, with only a few clicks. Additionally, some plugins
come with optimization features to ensure the best
performance.

In addition to databases, search engines can also query and


retrieve information. However, the term query in these two
technologies differs.
Web search query refers to keywords that users type in the search
engine, while database query is a particular action to make a
request for information.
Now that you understand the basic fundamentals of queries, let’s
study several standard terms you might come across when
querying a database:

 Query string – a portion of URL to pass requests from the


web to the database.

 Query parameters – elements attached to the end of an URL


to specify a particular query on the database.
 Query folding – refers to a process where the Power
Query is enabled to transform complex calculations for query
optimization.

 Query containment – happens when one query is contained


in another, if it is independent of the stored data values.

QUERY LANGUAGES
As mentioned before, choosing the database and its language is
crucial when working with queries. In addition to SQL, there is
another type of database called NoSQL (Not Only Structured Query
Language). The main difference between the two is the data
structure.
SQL databases are relational and use predefined schemas that
require you to specify your data structure. On the other hand,
NoSQL databases are non-relational and have dynamic schemas
for unstructured data.
Regardless, both SQL and NoSQL provide applicable options. An
SQL database is a great choice for an ACID-compliant  data
structure. Conversely, if you have unstructured documents, key-
values, or graphs, a NoSQL database might be an ideal choice.

QUERY EXAMPLES
Before we delve into the examples, below are the main benefits of
using a query:

 Review data from multiple tables simultaneously.

 Filter records containing only certain fields and of certain


criteria.

 Automate data management tasks and perform calculations.

Now, let’s suppose you have collected some data from a survey.
Below is a snippet of your data. Note that for this example, we will
use an SQL database.
Data source: Participant (Table Name)
ID Name Sex Age Occupation

1 John Male 17 Student

2 Peter Male 26 Unemployed

3 Margareth Female 34 Teacher

4 Lea Female 34 Unemployed


Selecting Only the “Name” and “Occupation” Columns From
the “Participant” Table
This example shows you how to create a select query that only
returns the value for Name and Occupation. The SQL statement
should look something like this:

SELECT Name, Occupation FROM Participant

The statement above filters specific data from the table. It will
generate the following result table:

Name Occupation

John Student

Peter Unemployed

Margareth Teacher

Lea Unemployed
-REFERENCE:

- Dec 07, 2022


Nabilla R.
What Is a Query? Database Query Explained
(hostinger.com)

You might also like