有三个表,结构分别如下
A:
CommentID int ,
TopicID int ,
TopicType tinyint ,
Content ntextB:
TopicID int,
Title nvarvhar(100)
C:
TopicID int ,
Title nvarchar(100)其中A表的TopicID字段对应B,C表的TopicID字段,A表的TopicType字段用于区分TopicID字段是属于B表还是C表,我现在要的查询效果是:
查询A表中的所有记录,与B,C表中对应的Title字段,并且A表中的TopicID,TopicType字段不发生重复。(其实也就是不产生重复的标题[Title])
A:
CommentID int ,
TopicID int ,
TopicType tinyint ,
Content ntextB:
TopicID int,
Title nvarvhar(100)
C:
TopicID int ,
Title nvarchar(100)其中A表的TopicID字段对应B,C表的TopicID字段,A表的TopicType字段用于区分TopicID字段是属于B表还是C表,我现在要的查询效果是:
查询A表中的所有记录,与B,C表中对应的Title字段,并且A表中的TopicID,TopicType字段不发生重复。(其实也就是不产生重复的标题[Title])
解决方案 »
- 树形结构的部门信息,以递归的方式存在数据库里。程序界面怎么管理?
- 很奇怪的事,想不出原因....求助!!
- 存储过程执行的顺序
- 求存储过程:根据某Access数据库中的一个表 将结构和数据导入到MSSQL
- 请教一个SQL Server 2005事务问题
- "select top 10 * from (select rid from reg where yesno=0) as a" 怎么取得影响行数
- 请教:添加数据时如何写入自动编号!用SQL语句!
- 这样的查询怎么写,谢谢了先!!
- 很复杂的sql问题
- 病入膏肓,在线急等
- 如何检索指定列不重复的记录
- 存储过程-SQL语句的CASE语句怎么用???在线等
from ta a left join tb b on a.topicid=b.topicid
left join tc c on a.topicid=c.topicid
title
from
(select * from a
where topictype = 'B') tab1
inner join b on
tab1.title = b.title
union
select TopicID ,
title
from
(select * from a
where topictype = 'A') tab2
inner join C on
tab2.title = C.title
union