Understanding the OFFSET Clause in Oracle

In Oracle Database, we can use the OFFSET clause to make a SELECT statement skip a certain number of rows in its result set.

The OFFSET clause is defined as part of the FETCH row limiting clause, which allows us to limit the number of rows returned by a query.

We can therefore use both OFFSET and FETCH to limit the output to just the specified number or percentage of rows, at a specified offset.

Continue reading

3 Ways to Fix “A TOP can not be used in the same query or sub-query as a OFFSET” Error in SQL Server

If you’re getting an error that reads “A TOP can not be used in the same query or sub-query as a OFFSET” when running a query in SQL Server, it’s probably because you’re using the TOP() clause and the OFFSET clause in the same query or sub-query.

We can’t use the TOP() clause and the OFFSET clause in the same query in SQL Server.

Below are three options for fixing this error.

Continue reading

How to Fix “The function ‘LAG’ must have an OVER clause” Error in SQL Server

If you’re getting an error that reads “The function ‘LAG’ must have an OVER clause” in SQL Server, it’s probably because you’re calling the LAG() function without an OVER clause.

The LAG() function requires an OVER clause (and that clause must have an ORDER BY clause).

To fix this issue, be sure to include an OVER clause when calling the LAG() function.

Continue reading

RANK() vs DENSE_RANK() in SQL: What’s the Difference?

Many RDBMSs include both a rank() and a dense_rank() function in their list of window function offerings. At first glance, these functions might appear to do the same thing. However, there’s one important difference between these functions, and you will definitely need to be aware of this difference when choosing which function to use.

Continue reading