What is DQL?

We often hear terms like DDL, DML, DQL, TCL, and DCL when using relational database management systems (RDBMSs). But what exactly are they?

In this article we’ll look at what DQL stands for, and what it does.

What Does DQL Stand For?

In the context of SQL, DQL stands for Data Query Language.

DQL is just one of the various initialisms we can find in SQL. Others include DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).

What Does DQL Do?

Data Query Language is used to perform queries against the data stored in a relational database.

DQL includes the SELECT statement, as well as a variety of operators and functions that can be used to manipulate the retrieved data. The SELECT statement is typically used to retrieve data from one or more database tables, and it can contain various clauses that specify the exact data to retrieve as well as how it is presented when it’s returned.

DQL Example

Here’s an example of a DQL statement:

SELECT * FROM Cats;

That DQL statement selected all rows and columns from a table called Cats. The asterisk (*) is a wildcard character that is used to select all columns.

All rows were returned because we didn’t specify any criteria to filter the rows to be returned.

Here’s an example of being more specific with our SQL statement:

SELECT CatName 
FROM Cats
WHERE Color = 'Yellow';

This statement returns the cat name of yellow cats only. We used the WHERE clause to narrow it down to just those where the Color column has a value of Yellow.

DQL vs DML

As seen above, DQL is used to select data from our database. But there’s also another subset of SQL we refer to as DML. DML stands for Data Manipulation Language and it is used to manipulate data.

The difference between DQL and DML can be a little blurred when it comes selecting data. The SELECT statement is widely considered to be a DML statement, but strictly speaking, it’s a DQL statement. Some say that once we start adding various clauses to the SELECT statement, it becomes a DML statement, perhaps due to the data being manipulated by the clauses.

Some of the clauses that we can add to a SELECT statement include:

  • FROM – specifies the table(s) from which to retrieve data
  • WHERE – filters the rows to be retrieved based on specified conditions
  • ORDER BY -sorts the retrieved rows based on one or more columns
  • GROUP BY – groups the retrieved rows based on one or more columns
  • HAVING – filters the groups produced by the GROUP BY clause

That said, most DML statements are clear cut. For example, the following statements are all considered DML statements, due to the fact that they actually manipulate data in the database:

  • INSERT – used to add new rows of data to a table.
  • UPDATE – used to modify existing data in a table.
  • DELETE – used to delete rows from a table.

That’s just a small subset of the many DML statements available.