sql多表查询语句,显示不重复数据

2024-11-27 17:13:31
推荐回答(5个)
回答1:

按照你给的代码,只要加个HAVING 就可以了。
比如下面所示:

ALTER PROCEDURE [dbo].[pro_GetText_One]
@firId int,
@secId int
AS
BEGIN
SELECT distinct text_Text.tId,text_Discuss.SendTime FROM text_Discuss inner JOIN
text_Text ON text_Discuss.tId = text_Text.tId where text_Text.firId=@firId and text_Text.secId=@secId
HAVING COUNT(text_Text.tId)>1
END

眼镜都看疼了,如果是对的,请多给点分!!

回答2:

这得看你要哪些字段的数据了
你要明白,这两表的关系是一对多的关系,所以在查询的时候如果两表字段都有出现,必然会有重复的

回答3:

ALTER PROCEDURE [dbo].[pro_GetText_One]
@firId int,
@secId int
AS
BEGIN
SELECT distinct text_Discuss.SendTime ,text_Text.tIdFROM text_Discuss inner JOIN
text_Text ON text_Discuss.tId = text_Text.tId where text_Text.firId=@firId and text_Text.secId=@secId and text_Text.tId in(select distinct tId from text_Text)
END

这样试一下

回答4:

group by 语句.
SELECT text_Text.tId,text_Discuss.SendTime FROM text_Discuss inner JOIN
text_Text ON text_Discuss.tId = text_Text.tId where text_Text.firId=@firId and text_Text.secId=@secId group by text_text.tld

回答5:

text_Text是留言表?