user1894647
user1894647

Reputation: 663

Remove all the duplicate values in MYSQL table

mysql format :

        jcid_no           die_no          qty
       jcid-085951         12345            2
       jcid-085951         12345            2

Friends I've a table format as the above , I'll be continuously inserting the values into the table but my requirement is I can insert n times same number of same jcid_no and die_no but not on the same row .

Valid example:

        jcid_no           die_no          qty
       jcid-085951         12345            2
       jcid-085951         54321            2


        jcid_no           die_no          qty
       jcid-085951         12345            2
       jcid-984301         12345            2

Same jcid_no different die_no and same die_no different jcid_no is ok but as if now my table got cluttered by have same table values multiple times my requirement is first I have to delete all the duplicate values that has been already inserted (i.e)

Wrong Format :

        jcid_no           die_no          qty
       jcid-085951         12345            2
       jcid-085951         12345            2

and the second thing is preventing this duplication for further enter , I use PHP as my front end .

Upvotes: 1

Views: 58

Answers (1)

Daniel Walter
Daniel Walter

Reputation: 815

To avoid further faulty values try using combined primary key like

PRIMARY KEY (jcid_no, die_no)

To delete double values try it with self join delete.

Upvotes: 1

Related Questions