默认使用 SELECT 语句;

Mysql的select in会自动过滤重复的数据

 当加上in范围后,结果如下图:

Mysql的select in会自动过滤重复的数据

in范围内的数据,如果有重复的,只会选择第一个数据。

所以如果不是直接使用SQL语句来查询,而是在代码中来查询时,记得使用 distinct 关键字

如:

select id, name from table1 where ref_id in (
     select id from table2   
)

其实是相当于:

select id, name from table1 where ref_id in (
     select distinct id from table2   
)

因为table2中的id可能会存在重复的情况。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-10-10
  • 2021-10-03
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-02-18
  • 2021-12-26
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案