Skip to content

Little victories

One little piece of sql code that I’d been trying to make work was bringing data into my join tables from the appropriate rows in the tables to be joined. After some struggles, I had success! The steps (and successful result) are behind the cut, mostly for my memory and the possible benefit of my classmates.  So this: select document.kp_doc_id, person.kp_pers_id from document, person where document.doc_sender=person.name_full successfully outputs the two columns of data I want to insert into two fields in a join table. The problem is how do I get them into the join table?

select document.kp_doc_id, person.kp_pers_id into sender(sender_doc_id, sender_pers_id) from document, person where document.doc_sender=person.name_full Does not work. I get undeclared the following error: ERROR 1327 (42000): Undeclared variable: sender

Tried this: INSERT INTO sender (sender_doc_id, sender_pers_id) SELECT document.kp_doc_id, person.kp_pers_id FROM document, person WHERE document.doc_sender=person.name_full and IT WORKED!