0

I was trying to insert rows into a table called subjects , i wrote the following query so that the duplicates can't occur. But this is not working.

INSERT INTO subjects ( stu_id, sub_id ) VALUES (16, 39) 
WHERE NOT EXISTS ( SELECT * FROM subjects WHERE stu_id = 16 AND sub_id = 39 );
Professor Abronsius
  • 26,348
  • 5
  • 26
  • 38
Anvesh
  • 11
  • 2

1 Answers1

0
INSERT IGNORE INTO subjects ( stu_id, sub_id ) VALUES (16, 39) 

This will ignore the data, if there are allready rows with that kind of data-combnation in a unique key.

DocRattie
  • 1,314
  • 2
  • 13
  • 24