简体   繁体   中英

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. 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.

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.
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.
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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