防止重复的行 [英] prevent duplicate rows

查看:59
本文介绍了防止重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好亲爱的



我有一个带两张桌子的数据库(record_table,附件)



< b> record_table

 ID,subject,note 





附件

<前lang =text> ID,ID_record_table,路径





表之间的关系:

 record_table.id = attachment.ID_record_table 







但是当record_table中的一行有2个附件时。当我使用select语句时,我会在record_table中看到同一行的2个结果。所以如何防止重复行。



 SELECT  * < span class =code-keyword> FROM  record_table  LEFT   JOIN  attachment   record_table.id = attachment.ID_record_table)

解决方案

因为你加入了这两个在结果集中,您将获得多少行,以满足连接条件的行数。换句话说,如果一个记录有两个附件,则返回两行.-



这些行不是重复的。如果您查看来自附件表的列,您会看到包含两行中的值。



看看 SQL连接的可视化表示 [ ^ ]


试试这个,



sql - 加入两个表并显示全部记录 - 堆栈溢出 [ ^ ]

hello dears

I have one database with two tables (record_table,attachments)

record_table

ID, subject,note



attachments

ID, ID_record_table,path



relationship between tables:

the record_table.id = attachment.ID_record_table




but when one row in record_table has 2 attachment .and when I use select statement i will see 2 results for the same row in record_table. so how can I prevent duplicate rows.

(SELECT * FROM record_table LEFT JOIN attachment on record_table.id = attachment.ID_record_table)

解决方案

Since you're joining the two tables you will get as many rows in the result set how many rows satisfy the join condition. In other words, if one record has two attachments, two rows are returned.-

The rows aren't duplicates. If you have a look at the columns coming from attachment table you see that the contain the values from both rows.

Have a look at Visual Representation of SQL Joins[^]


try this,

sql - join two tables and show all records - Stack Overflow[^]


这篇关于防止重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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