我有以下查询:
select
t1.x,
t2.y
from table1 t1
join table2 t2
on t1.x = t2.x
产生以下结果:
x y1
x y2
x y3
但是,我希望它产生以下内容,其中来自 t1.x 的值也在第二列中:
x x
x y1
x y2
x y3
是否有捷径可寻?我试图在 PostgreSQL 中实现这一点,但我也对 MySQL 中的任何解决方案感兴趣。
提前致谢!
你似乎想要:
select t1.x, t1.x as y
from table1 t1
union all
select t2.x, t2.y
from table2 t2;
的join
,如果你想过滤器(或多次)行的基础上,只需要x
两个表中存在。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句