I am trying to run a query that essentially looks like this:
INSERT INTO lessons_skills_xref (lessons_id, skills_id)
SELECT id FROM lessons, (SELECT id FROM skills WHERE title = "title 1")
/* PSEUDO CODE - Where the ids for both lesson and skill don't already exist */
Not sure how to accomplish the last part. Any ideas?
Assuming
lessons_skills_xrefhas a unique key on (lessons_id,skills_id), an easy way would be to just useINSERT IGNOREThe
INSERT IGNOREsyntax will insert the record if it doesn’t already exist, or ignore it if it’s already there.