我想显示两个连接表的所有列,但只从其中一个列(即antsDescriptionCode
)检索具有nvarchar
数据类型的唯一值。SQL - 如何检索连接表中的唯一值(nvarchar)?
任何人都可以请帮忙吗?谢谢。
我对当前的查询,让我显示所有列两个连接表中的一些条件:
select c.*, a.*
from cats c
join ants a on c.ctypeid = a.atypeid
where
(c.CatsNo like 'cat4%'
or c.CatsNo like 'cat7%'
or c.CatsNo like 'cat8%')
and a.antsflagged = 0
and a.antsDescriptionCode in ('type a', 'type b', 'type c')!
Refer to image for current get and expected output
我使用Microsoft SQL Server 2008
您可以添加您当前获得的输出示例以及您想要获得的输出吗? – Blorgbeard 2012-08-15 03:19:23
嗨@Blorgbeard 我已更新我的问题。 fyi,我是新来的,不知道如何在我的问题/评论中显示表格,所以我上传了一个文件供您参考。谢谢。 – ayuicyi 2012-08-15 05:04:40
什么类型的数据库? AntsDescriptionCode对应于多个记录,它应该如何确定要为每个AntsDescriptionCode返回哪条记录?这是有点不清楚你在找什么。 – 2012-08-15 05:20:19