Limit rows with distinct

9 views
Skip to first unread message

livius...@poczta.onet.pl

unread,
Dec 17, 2025, 5:53:22 PM (2 days ago) Dec 17
to firebird...@googlegroups.com
Hi

i am curious if

1. 
SELECT
DISTINCT X.NAME
FROM
TABLE_X X
ROWS 2

is equal to

2. 
SELECT
FROM
(
SELECT
DISTINCT X.NAME
FROM
TABLE_X X
) Y
ROWS 2

or maybe it is

3.
SELECT
DISTINCT Y.NAME
FROM
(
SELECT
FROM
TABLE_X X
ROWS 2
) Y

And is it always one of these cases, regardless of the query plan?

I’m fairly sure the answer is “2,” but I need to be certain.

To make the question a bit more complex, consider different LIMIT-style clauses:


a) rows:
SELECT
DISTINCT X.NAME
FROM
TABLE_X X
ROWS 2


b) first:
SELECT
FIRST 2 DISTINCT X.NAME
FROM
TABLE_X X

c)  fetch:
SELECT
DISTINCT X.NAME
FROM
TABLE_X X
FETCH FIRST 2 ROWS ONLY

regards,
Karol Bieniaszewski
Reply all
Reply to author
Forward
0 new messages