databend icon indicating copy to clipboard operation
databend copied to clipboard

bug: Duplicated table name numbers in the same FROM clause

Open zhang2014 opened this issue 6 months ago • 1 comments

Summary root@localhost:8000/default> select * from (select number as a from numbers(10)), (select number as b from numbers(2)); error: APIError: QueryFailed: [1065]Duplicated table name numbers in the same FROM clause

zhang2014 avatar Jun 18 '25 05:06 zhang2014

I tried this SQL in Snowflake and Clickhouse, but both failed to execute.

Clickhouse prompted Code: 206. DB::Exception: JOIN , ... no alias for subquery or table function SELECT number AS a FROM numbers(10). In scope SELECT * FROM (SELECT number AS a FROM numbers(10)), (SELECT number AS b FROM numbers(2)) (set joined_subquery_requires_alias = 0 to disable restriction). (ALIAS_REQUIRED)

In fact, this SQL is indeed as ClickHouse suggests, and does not explicitly distinguish table names to differentiate numbers.Therefore, after modifying the SQL to

SELECT * 
FROM 
(SELECT number AS a FROM numbers(10)) AS t1,
(SELECT number AS b FROM numbers(2)) AS t2;

both ClickHouse and Databend can execute it.

KKould avatar Jun 19 '25 03:06 KKould