e.g.:this is table t1 and t2 data.
:] select * from t1;
SELECT *
FROM t1
ββxββ¬βyββββ
β 1 β aaa β
βββββ΄ββββββ
ββxββ¬βyββββ
β 2 β bbb β
βββββ΄ββββββ
β Progress: 2.00 rows, 32.00 B (635.66 rows/s., 10.17 KB/s.)
2 rows in set. Elapsed: 0.003 sec.
:] select * from t2;
SELECT *
FROM t2
ββxββ¬βyβββββ
β 2 β bbbb β
βββββ΄βββββββ
ββxββ¬βyβββββ
β 3 β cccc β
βββββ΄βββββββ
β Progress: 2.00 rows, 34.00 B (638.61 rows/s., 10.86 KB/s.)
2 rows in set. Elapsed: 0.003 sec.
I need select t1.x and t2.x,ClickHouse can't support alias . how to fix this problem
:] select x,y,y from (select x,y from t1) as t1 any inner join (select x,y from t2) as t2 using x;
SELECT
x,
y,
y
FROM
(
SELECT
x,
y
FROM t1
) AS t1
ANY INNER JOIN
(
SELECT
x,
y
FROM t2
) AS t2 USING (x)
ββxββ¬βyβββββ¬βyβββββ
β 2 β bbbb β bbbb β
βββββ΄βββββββ΄βββββββ
β Progress: 4.00 rows, 42.00 B (370.81 rows/s., 3.89 KB/s.)
1 rows in set. Elapsed: 0.011 sec.
:]
:] select x,y,yy from (select x,y,y as yy from t1) as t1 any inner join (select x,y from t2) as t2 using x;
SELECT
x,
y,
yy
FROM
(
SELECT
x,
y,
y AS yy
FROM t1
) AS t1
ANY INNER JOIN
(
SELECT
x,
y
FROM t2
) AS t2 USING (x)
ββxββ¬βyβββββ¬βyyβββ
β 2 β bbbb β bbb β
βββββ΄βββββββ΄ββββββ
β Progress: 4.00 rows, 66.00 B (418.75 rows/s., 6.91 KB/s.)
1 rows in set. Elapsed: 0.010 sec.
:]
My god...is very trouble. I need query this column again add alias .
This is very diff standard SQL
Here is a way to do it in ClickHouse:
:) SELECT x, y1, y2 FROM (SELECT x, y AS y1 FROM t1) ALL INNER JOIN (SELECT x, y AS y2 FROM t2) USING (x)
SELECT
x,
y1,
y2
FROM
(
SELECT
x,
y AS y1
FROM t1
)
ALL INNER JOIN
(
SELECT
x,
y AS y2
FROM t2
) USING (x)
ββxββ¬βy1ββ¬βy2ββ
β 1 β t1 β t2 β
βββββ΄βββββ΄βββββ
1 rows in set. Elapsed: 0.002 sec.
Most helpful comment
Here is a way to do it in ClickHouse: