questdb icon indicating copy to clipboard operation
questdb copied to clipboard

Wrong results on DISTINCT on subqueries

Open TheTanc opened this issue 2 years ago • 1 comments

Describe the bug

I am getting wrong query results on subqueries using DISTINCT

To reproduce

Consider the following query

SELECT DISTINCT TICKER FROM TABLEA 
UNION
SELECT DISTINCT TICKER FROM TABLEB
UNION
SELECT DISTINCT TICKER FROM TABLEC 

Results may be tickerA1, TickerA2, TickerB1, TickerB2, TickerC1, TickerC2

However, consider the following:

SELECT DISTINCT TICKER FROM 
(
SELECT DISTINCT TICKER FROM TABLEA 
UNION
SELECT DISTINCT TICKER FROM TABLEB
UNION
SELECT DISTINCT TICKER FROM TABLEC 
)

Results are

Results may be tickerA1, TickerA2

Expected Behavior

In this case, the tickers across tables A,B,C are all unique. So I expect the same result for both queries. In case there were duplicates, I would expect the query results to be the unique list of tickers across all 3 tables.

Environment

- **QuestDB version**: 6.3.1
- **OS**:Windows server
- **Browser**: n/a

Additional context

No response

TheTanc avatar May 30 '22 16:05 TheTanc

Hi @TheTanc could you double check whether this is fixed by #2123 in 6.4.1? Thanks!

pswu11 avatar Jun 15 '22 15:06 pswu11

@pswu11 I tested the given queries and the issue seems to be fixed, probably by the mentioned PR.

Belair34 avatar Oct 11 '22 15:10 Belair34

Thanks a lot @Belair34 for confirming!

pswu11 avatar Oct 11 '22 17:10 pswu11