2016-07-29 179 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次的嘗試這個 –