我有一张内容表content,有字段ID
一张分类表category,有个字段是tableName
还有其它的表等,其中都有一个contentID字段,对应content表中的ID我现的语句是想查询内容表中的内容,并关联其它表(未知名称,需要从category中的tableName读取)我是这样写的,但是不行,试了N多了,想不出了这个sql语句select c.*,t.* from content c left join (select * from (select ca.custom_table from category ca where ca.ID = 8)) t on t.contentId = c.ID where c.ID=8请帮忙分析一下,错在哪,或正确的写法
一张分类表category,有个字段是tableName
还有其它的表等,其中都有一个contentID字段,对应content表中的ID我现的语句是想查询内容表中的内容,并关联其它表(未知名称,需要从category中的tableName读取)我是这样写的,但是不行,试了N多了,想不出了这个sql语句select c.*,t.* from content c left join (select * from (select ca.custom_table from category ca where ca.ID = 8)) t on t.contentId = c.ID where c.ID=8请帮忙分析一下,错在哪,或正确的写法
这个xxxx表名是要从categroy中取得,而内容表content都有个catId,和catgory表的ID对应就是查询过程应该是怎么样假如现在我要查一条内容content表ID为8的记录,他会从ID为8的content表中查出这条记录对应的catId,然后再根据catId从category中查出tableName为xxxx,然后这个xxxx表中contentID为8的记录left join到这个查询中.
不知我讲清楚没.我试过N多种写法,还是不行
union
select 'tabelName2',* from tableName2
...然后和你的content一起做联合查询即可。
.
[align=center]==== 思想重于技巧 ====
[/align]
.
贴子分数<20:对自已的问题不予重视。
贴子大量未结:对别人的回答不予尊重。
.
from content c
left join (
select * from
(select ca.contentId ,ca.custom_table from category ca where ca.ID = 8)) t
on t.contentId = c.ID where c.ID=8