简体   繁体   English

在联接的mysql查询结果中获取表名

[英]Getting table name in joined mysql query result

SELECT
*
FROM table1
LEFT JOIN table2
ON table1.id=table2.ref

How to distinctly identify column which are from table1 or table2. 如何区分来自table1或table2的列。 Is there anyway to get table name in alias which can be used to identify column by table name?If it matters i am using PHP to fetch from database. 无论如何,是否有别名获取表名,该别名可用于按表名标识列?如果有关系,我正在使用PHP从数据库中获取数据。

Well, your reason is fair but the implementation is unusual. 好吧,你的理由很公平,但是实现却不寻常。

When each table represents a class in php, it is called ORM - Object-relational mapping. 当每个表代表php中的类时,它称为ORM-对象关系映射。
And when it is used, an object already knows it's fields, because each table being only a reflection of the class properties. 并且当使用它时,一个对象已经知道它的字段,因为每个表只是类属性的反映。 Frankly, with ORM nobody is going to create tables manually - they are created (or altered) based on the object properties. 坦白地说,使用ORM,没人会手动创建表-它们是根据对象属性创建(或更改)的。
So, an object always can tell it's fields from others. 因此,一个对象总是可以区分其他对象的字段。

As for your literal question - no, there is no way to get such info, as far as I know 至于您的字面问题-据我所知,没有办法获取此类信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM