Thursday, 26 October 2017

How to select distinct rows without using group by statement

A B C1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 66 6 6 I am to output only the distinct rows without using the group by statement. I cannot use group by because it makes mysql hang. So it should return1 1 12 2 2 3 3 3 4 4 4 5 5 5 6 6 6 Solutions: If the name of your table is mytable , select distinct * from mytable will do the trick. MySQL uses GROUP BY under the hood to execute DISTINCT !!! If the table is called mytable, do these two things:First run thisALTER TABLE mytable ADD INDEX ABC (A,B,C);`Second, run this...