为连接编写一个避免重复行的过程 [英] write a procedure for joins which avoids duplication of rows

查看:58
本文介绍了为连接编写一个避免重复行的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我基于联接发布了一个问题,
但是在编写完程序之后,我发现重复的列还在进行中.

您能指导我如何使用分组依据"来避免重复吗?


谢谢您的答复,我必须学习新的概念.

Previously I have posted a question based on joins,
but after writing the procedures I found there are duplication of columns going on.

Can you please guide me how do I use "group by" to avoid the duplications.


Thank you for the response, I got to learn new concepts.

推荐答案

如果您在SQL中联接表,其中表一与表二具有一对多关系,那就是您观察到的自然而然.另一方面,如果您要谈论的是重复的行,而整个行都是重复的,则可以通过使用SELECT DISTINCT来避免:

If you JOIN tables in SQL where table one has a one to many relationship to table two it is only natural what you are observing. If on the other hand you''re talking about duplicate rows where whole rows are duplicated, this can be avoided by using the SELECT DISTINCT:

SELECT DISTINCT a.YearId, a.codeid, a.linkid, a.code, a.codename, a.AcctType,
                b.CodeId, b.Code, b.CodeName, 
                c.Codeid, c.code, c.Codename,
                d.FYId
FROM FinancialYear d, Accounts a 
    LEFT JOIN Accounts b ON(b.linkid=a.codeid)
    LEFT JOIN Accounts c ON(c.linkid=a.codeid)
WHERE
    a.YearId=d.FYId and
    b.CodeId=a.CodeId and
    a.linkid=6 and
    a.CodeId=9 and
    a.flag<>0 and
    a.accttype='R'



干杯!



Cheers!


这篇关于为连接编写一个避免重复行的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆