2016-07-29 13 views
0

该查询适用于SQL Server,但在MySQL中不起作用。任何人都可以帮忙吗?在MySQL中选择重复记录

SELECT name 
FROM table_name 
WHERE 
    Institution_Code = 1 and 
    Month= 6 and Year= 2016 and 
    Id IN (
      SELECT Id FROM table_name 
      where Institution_Code = 1 and 
       Month= 6 and Year= 2016 
      GROUP BY Id HAVING count(Id) > 1 
     ) 

回答

0

试图逃跑的保留字查询:

SELECT name 
FROM table_name 
WHERE Institution_Code = 1 
and `Month`= 6 
and `Year`= 2016 
and Id IN (
    SELECT Id 
    FROM table_name 
    where Institution_Code = 1 
    and `Month`= 6 
    and `Year`= 2016 
    GROUP BY Id 
    HAVING count(Id) > 1) 
0

做这样的:

SELECT name 
FROM table_name 
WHERE Institution_Code = 1 
and [Month]= 6 
and [Year]= 2016 
and Id IN (
    SELECT Id 
    FROM table_name 
    where Institution_Code = 1 
    and [Month]= 6 
    and [Year]= 2016 
    GROUP BY Id 
    HAVING count(Id) > 1) 

SQL保留字必须附上该支架[保留字在这里]

0

你可以试试这个

SELECT * , count('name') is_duplicate 
FROM `tbl_name` 
GROUP BY `name` 
HAVING is_duplicate >1 
+0

没有工作,那么整个显示的数据,但我想只是重复数据 – Anup

+0

让我更新我的答案 –

+0

SELECT *,COUNT( '名')is_duplicate FROM'tbl_name' GROUP BY'name' HAVING is_duplicate> 1次的尝试这个 –