Support DISTINCT with correlated subqueries
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 616
- Avg merge
- 14h 49m
- Merged PRs (30d)
- 206
Description
### Problem Statement
The script below fails with `UnsupportedFeatureException[Cannot use correlated subquery in GROUP BY clause]`
```sql
CREATE TABLE tbl1 (a TEXT,fk INTEGER);
INSERT INTO tbl1 VALUES ('abc',1);
REFRESH TABLE tbl1;
CREATE TABLE tbl2 (id INTEGER,b TEXT);
INSERT INTO tbl2 VALUES (1,'def');
REFRESH TABLE tbl2;
SELECT DISTINCT a
,( SELECT b
FROM tbl2
WHERE id = fk
)
FROM tbl1;
```
### Possible Solutions
Support this as in PostgreSQL
```
postgres=# select distinct a,(select b from tbl2 where id=fk)
postgres-# from tbl1;
a | b
-----+-----
abc | def
(1 row)
```
### Considered Alternatives
- Storing the results in a "temporary" table then run the `DISTINCT` on it
- Use JOINs
Contributor guide
Assessment
This issue has not been assessed yet.