What is a query: what is a complete database query

The word query refers to a request for information. Then, what is a query in a computer programming language? Basically, the meaning of query in everyday English and computer programming language has the same meaning – except on computers, queries include information received or retrieved from a database. This programming language is useful for manipulating data – adding, deleting, and modifying data.

When creating a query, you cannot just type ‘request’ carelessly. Queries are written based on a set of pre-defined code so that the database can understand the requested instructions. We call this code the query language.

The standard for database management is Structure Query Language (SQL). One thing you should remember, SQL is different from MySQL : SQL is a query language, MySQL is the software that uses that language. SQL is known as the most widely used database software. However, SQL is not the only software option. AQL, Datalog, and DMX are examples of database software that you can use.

However, the above programming languages ​​make database communication easy.

Is it your first time creating a website? We provide web hosting packages that are rich in features and are perfect for simple businesses as well as novice developers who want to practice their skills.

More details

Contents

  • How Do Queries Work?
  • Example Query
  • Conclusion

How Do Queries Work?

Let’s say you are going to order an Americano at Starbucks. When standing in front of the barista, you will definitely say, “Order Americano, yes ?!”. The barista understands your request and immediately makes Americano.

Queries work the same way as when you order Americano. Queries insert meaning into code used in various query languages. Whether it’s SQL or other software, both the user and the database can always exchange information as long as they both use the same language.

Maybe you think that the query is the only way to request (request) data. In fact, there are some software that offer other methods. Here are some ways that are often used:

  • Using the provided parameters.

By default, the software has a list of parameters in its menu. The user can select a list, and then the system will guide you to make the expected output. The process is easy, but inflexible and the operating system is limited.

  • Query by example

The system will display a code set with several blank areas. In the empty area, you can write and specify the fields and value data.

  • Query Language

If you want to manipulate data, you have to write queries from scratch. To use this method, at least you already have an understanding of the query language used by database software. Even though it’s difficult, at least you can fully control the data.

Example Query

After understanding the query, it’s a good idea to get right into practice. For the example query, we will use SQL.

Data source : Participants (Table Name)

Let’s say you have already conducted a survey and collected data. Below is a snippet of data information obtained.

ID Name Gender Age Profession
1 John Men 17 Students
2 Peter Men 26 Does not work
3 Margareth Woman 34 Teacher
4 Leah Woman 34 Does not work

Procedure

With SQL, you can write SQL SELECT or SQL ACTION queries. As the name suggests, SQL SELECT allows you to select portions of data, whereas SQL ACTION allows you to perform action-oriented operations, such as deleting and inserting data, updating values, and creating new tables. Here are some examples:

Just choose the “Name” and “Job” columns from the “Participants” table.

SQL Statement:

SELECT Name, Job FROM Participant

Output:

Name Profession
John Students
Peter Does not work
Margareth Teacher
Leah Does not work

Delete the data of respondents who do not work.

SQL Statement :

DELETE FROM Participant WHERE Job = ‘Not Working’

Output:

ID Name Gender Age Profession
1 John Men 17 Students
3 Margareth Woman 34 Teacher

Enter a new line containing the participant named Mario.

SQL Statement :

INSERT INTO Participant (ID, Name, Gender, Age, Occupation) VALUES (‘5’, ‘Mario’, ‘Male’, ’67’, ‘Retired’)

Output:

ID Name Gender Age Profession
1 John Men 17 Students
2 Peter Men 26 Does not work
3 Margareth Woman 34 Teacher
4 Leah Woman 34 Does not work
5 Mario Men 67 Pension

Changed Margaret’s job to “Headmaster”.

SQL Statement :

UPDATE Participants SET Job = ‘Head of School’ WHERE ID = ‘3’

Output:

ID Name Gender Age Profession
1 John Men 17 Students
2 Peter Men 26 Does not work
3 Margareth Woman 34 Headmaster
4 Leah Woman 34 Does not work

Conclusion

Several SQL statements, such as the one exemplified above, are strong evidence of the usefulness of queries. You can also organize your data more effectively. Just imagine if now you have thousands of data, of course manipulating it using a query language will not be that difficult. On the other hand, most query languages ​​are intuitive, and that means they are easy to learn if you already understand and understand the basic rules or concepts.

 

Leave a Comment

Scroll to Top