我如何从此表中检索唯一记录?

发布于 2024-11-17 11:54:24 字数 270 浏览 8 评论 0原文

我有两个表:CardInfo 和 CardItems,因此每个 CardInfo 可能有多个 CardItems。我需要一个 SQL 查询来根据与 CardInfo 和 CardItems 表相关的一些条件从 CardInfo 获取唯一记录。

select c.* from CardInfo c, CardItems ci
where c.cr_no = ci.cr_no and ci.wc_id = 'test'

上述查询返回重复记录。请提出解决方案。

I have two tables: CardInfo and CardItems, so each CardInfo may have multiple CardItems. I need a SQL query to fetch unique records from CardInfo on the basis of some conditions which relates with both CardInfo and CardItems tables.

select c.* from CardInfo c, CardItems ci
where c.cr_no = ci.cr_no and ci.wc_id = 'test'

The above query return duplicate records. Please suggest a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2024-11-24 11:54:24

您可以使用 DISTINCT 删除重复记录

select distinct c.* from CardInfo c, CardItems ci
where c.cr_no = ci.cr_no and ci.wc_id = 'test'

you can remove duplicate records with DISTINCT

select distinct c.* from CardInfo c, CardItems ci
where c.cr_no = ci.cr_no and ci.wc_id = 'test'
吻风 2024-11-24 11:54:24
   select c.* from cardinfo as c innerjoin carditems as ci
        on c.cr_no=ci.cr_no
where ci.wc_id = 'test'
   select c.* from cardinfo as c innerjoin carditems as ci
        on c.cr_no=ci.cr_no
where ci.wc_id = 'test'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文