如果employee表中的employee_no的字段有重复值,而实际情况又是不应该有重复值的,所以如果有重复值的话,就需要将它查出来,以下给出解决办法:
select employee_no,employee_name from employee
group by employee_no,employee_name
having count(employee_no)>1
order by employee_no
这里利用的是group 语句与having语句的结合。这样就可以将重复值查询出来。
上面的代码只能将重复的值查出来(只取重复值的一个)如果要将所有重复值都取出来,可用以下代码:
select * from temp_emp_tvs
where employee_no in(
select employee_no from temp_emp_tvs
group by employee_no,employee_name,tvs_name
having count(employee_no)>1
)
order by employee_no