Select 来自多个 table,结果标记为 table

Select from multiple tables with results labeled by table

是否有任何方法可以执行 MySQL 多 table select 可以 tag/label 来自 table 列的列?

table1
tID   name    desc
---------------------
1    foo     lots of foo
2    bar     lots of bar
3    foobar  none of these

table2
oID   tID    orderNo
------------------------
1    1       19001
2    1       19002
3    3       19004
4    2       19005

SELECT t1.*, t2.* FROM table1 t1,table2 t2 WHERE t1.tID=t2.tID ;

输出将是:

tID    name    desc            oID      orderNo
-----------------------------------------------
1      foo     lots of foo      1       19001
1      foo     lots of foo      1       19002
2      foo     lots of bar      4       19005
3      foo     none of these    3       19004

但我正在寻找输出如下的内容:

t1.tID    t1.name    t1.desc            t2.oID      t2.orderNo
---------------------------------------------------------------
1         foo        lots of foo        1           19001
1         foo        lots of foo        1           19002
2         foo        lots of bar        4           19005
3         foo        none of these      3           19004

这个小例子代表了我试图解决的一个更大的问题。它将允许一个查询,但也能够在解析数据时告诉我数据来自哪个table。

您可以为每一列使用别名,我建议编写一个适当的连接。

SELECT t1.tID as `t1.tID`,   
       t1.name as `t1.name`,   
       t1.desc as  `t1.desc`,  
       t2.oID  as `t2.oID`, 
       t2.orderNo  as `t2.orderNo`
FROM table1 t1
INNER JOIN table2 on  t1.tID=t2.tID ;