我有以下SQL查询:
with table_new as (
select a.id as a_id, b.id as b_id from table_a a
left outer join table_b b
on a.col_x = b.id
)
select * from table_new where b_id is null
上面的代码运行正常。但是,我希望table_new
显示已加入表格的所有列,而不仅仅是a_id
和b_id
。但是,连接表的列太多,不能在不使用select *
的情况下逐个键入每一列
所以我想知道如何在连接表中显示所有列,但只重命名其中两列(a.id as a_id, b.id as b_id
)?也就是说,我正在寻找类似的东西:
伪代码:
select *, a.id as a_id, b.id as b_id from table_a a
left outer join table_b b
on a.col_x = b.id
这可能吗?