Search code examples
mysqlsqlselectrownum

Display Serial Number (rownum) along with the data in mysql by eliminating the duplicates in my table?


I have a Table which contains duplicate data in one column. I want to display unique data along with the rownum or serial number. my table has fields table1(tno,tname), in where tname has duplicate values, and I want to display the unique 'tname' data.


Solution

  • Try this:

    SET @auto:=0;
    SELECT @auto:=@auto+1 rownum, tname 
    FROM table1 GROUP BY tname