How to Limit the Rows Returned by a SQL Query

When writing SQL queries, we’ll often use a WHERE clause or HAVING clause to narrow the results down to just those rows that we’re interested in.

But sometimes we might want to reduce the number of rows returned without adding extra filtering criteria. Sometimes we might just want to see a handful of rows, without hundreds, thousands or even millions of rows being returned.

Read more

How to Calculate the Mode in SQL

In statistics, the mode is the most commonly occurring value in a data set. When using SQL databases, we can easily run a SQL query to find out the mode of a given column.

Below are several options we can use to calculate the mode in SQL.

Read more

How to Use the DISTINCT Clause in SQL

Most of the major relational database management systems (RDBMSs) allow for a DISTINCT clause to be included in our SQL queries.

We use the DISTINCT keyword to return only unique rows. It eliminates duplicates from the results. If we have two or more rows with exactly the same data, we’ll only see one row in the results.

Read more

Understanding the LIMIT Clause in SQL

Some of the major relational database management systems (RDBMSs) have a LIMIT clause that enables us to reduce the number of rows returned by a query.

The way it works is that we provide the number of rows we want to be returned by the query. We can also provide an offset to specify which row to start the count from.

Read more