2
我有两个表:SQL - 表可以通过别名列/字段获取自己的名称吗?
产品:
id
图像:
id
imageable_type
imageable_id
我试图执行一个查询到的效果:
SELECT *
FROM product p
INNER JOIN image i
ON i.imageable_id = p.id
AND i.imageable_type = "product" # <--this
但由于我的应用程序框架的制约,我必须一个字段名称添加到别名p.
,所以我寻找的东西的影响:
AND i.imageable_type = p.TABLE_NAME # <--this
其中TABLE_NAME
是一些建于“通用专业领域”可谓是引用父表的名称。有没有像MySQL或其他SQL数据库的功能?
是否要在表格中返回表格名称? – Alex
@Alex不,我想加入哪里'i.imageable_type ='表名。 – bsapaka
在sql(或mysql)中,表名必须是显式的..您可以使用过程代码和dinamically生成的代码来执行此类事情。 – scaisEdge