Insert New Row in Table 3 if combination of Col A and Col B in Table C Don't Exist
I have a code that gets data from Tables 1 and 2, and then inserts new rows into Table 3. My problem is that the code adds records that already exist. How can I prevent duplicate errors from being inserted, when the combination of groupid and userid in Table C already exists? INSERT INTO mdl_groups_members (groupid,userid) SELECT l.mgroup AS moodle, r.id AS mdl_user FROM moodle AS l JOIN mdl_user AS r ON l.orders_id = r.id WHERE l.mgroup > 0 Here's the table before I ran the script: id groupid userid timeadded 1 1 1 1372631339 2 4 2 1372689032 3 8 3 1373514395 4 3 4 1373514395 Here's the table