开发者

How might I retrieve unique records from this table?

开发者 https://www.devze.com 2023-03-15 19:57 出处:网络
I have two tables: CardInfo and CardItems, so each CardInfo may have multiple CardItems. I need a SQL query to fetch unique records from CardInfoon the basis of some conditions which relates with both

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.


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'


   select c.* from cardinfo as c innerjoin carditems as ci
        on c.cr_no=ci.cr_no
where ci.wc_id = 'test'
0

精彩评论

暂无评论...
验证码 换一张
取 消