Nero909
Nero909

Reputation: 75

Does Snowflake DB support subqueries in FROM clause?

I have looked at their documentation and they do support subqueries but it is not clear if I can have a subquery in the FROM clause.

If so, can you please show me the proper syntax?

My query:


select C1 C1, 2 C2, 3 C3 
from 
( 
select X.*, *, Y.*, Y.SNO C1 
from Y, X 
) T1

Upvotes: 2

Views: 1014

Answers (1)

Marcin Zukowski
Marcin Zukowski

Reputation: 4719

It definitely does! Example below. If your query doesn't work, please provide a full repro case and an error message.

create or replace table x(i int) as 
select column1 from values(1),(1),(2),(3),(2);

select * from x, (select avg(i) from x);
---+--------+
 I | AVG(I) |
---+--------+
 1 | 1.800  |
 1 | 1.800  |
 2 | 1.800  |
 3 | 1.800  |
 2 | 1.800  |
---+--------+

select count(*) from (select distinct i from x);
----------+
 COUNT(*) |
----------+
 3        |
----------+

Upvotes: 2

Related Questions