Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我在 sql 查询中从三个唯一表中提取列。并说这些列具有相同的数据类型。有没有办法让我的结果中有一个额外的列来表示某行来自哪个表?比如 table_A 的 1,table_B 的 2,等等。我该怎么做?
SELECT "table1" which, colX the_col FROM table1 WHERE ... UNION SELECT "table2" which, colY the_col FROM table2 WHERE ... ...
select A.col as col_A, B.col as col_B from A join B;