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

An Introduction to the MEDIAN() Function in SQL

Some relational database management systems (RDBMSs) have a MEDIAN() function that calculates the median value within a range of values.

It returns the middle value or an interpolated value that would be the middle value once the values are sorted.

The SQL MEDIAN() function typically operates on numeric expressions, but depending on the RDBMS, may also operate on other data types, such as datetime expressions.

Depending on the RDBMS, the MEDIAN() function can be used as a window function, as an aggregate function, or as both.

Read more

Introduction to the PERCENTILE_DISC() Function in SQL

Some SQL databases have a PERCENTILE_DISC() function that calculates a percentile based on a discrete distribution of a range of column values.

We specify the percentile to use when we call the function.

Depending on the DBMS, PERCENTILE_DISC() can be used as a window function, as an aggregate function, or as both.

The PERCENTILE_DISC() function always returns a value from the underlying data. This is in contrast to the PERCENTILE_CONT() function, which can interpolate between adjacent values to return a value that’s not in the underlying data.

Read more