MySQL Select only redundant rows and keep the original rows

I have this table

ID | NAME | TICKETNO
---------------------
 1 | Issa   | K1
 2 | kassim | K1
 3 | Said   | G5
 4 | Maya   | G5
 5 | Sara   | G5
 6 | Kesi   | J8
 7 | Ima    | J8
 8 | Fali   | O9

      

And I want to execute a MySQL query to select only duplicates based on colum TICKETNO

and keep the original rows and create a table like this

ID | NAME | TICKETNO
---------------------
 2 | kassim | K1
 4 | Maya   | G5
 5 | Sara   | G5
 7 | Ima    | J8

      

Can someone give a MySQL query for this?

+3


source to share


1 answer


You can use the following solution:

SELECT * FROM table_name WHERE NOT ID IN ( 
    SELECT MIN(ID) FROM table_name GROUP BY TICKETNO
)

      



demo: http://sqlfiddle.com/#!9/b1941d/6/0

+2


source







All Articles