Skip to content
Advertisement

Incorrect first value when using dense_rank with union all

I want to ‘batch’ my result (coming from a union of several queries) with a predefined ‘batch size’ but I can’t figure out why the first batch is always incorrect?

For instance with the following code:

I get a result:

It seems like they’re all ok except for batch 1 which only consist of itemid 100? Must be doing something wrong here..

Advertisement

Answer

dense_rank() starts with 1. Shift it to start with 0 :

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement