I’m wondering if a link table can be populated automatically ? Here’s the example
Table1 is a list of movies (movie_id, name)
Table2 is a list of producers (producer_id, name)
Table3 is the link table (movie_id, producer_id)
When I insert into both the movies and the producers table, is there a way that the link table can be inserted with both ids automatically ? or do I have to do a select on both tables, then insert into Table3 ?
I assume once the database is populated, I will have to do selects on the producer table to see if he/she already exists, but for the time being, I’d like to know based on inserting into both tables.
true, that was 75% pseudo code anyway. The tables themselves will have a composite unique key to avoid exact duplicates.
I just read that stored procedures (which I’m trying to get my head around) have CASE ability, which might be another way to go for anyone referencing this thread.
I actually managed to create an insert with a select subquery from the two tables I needed… so I guess 1 insert is better than 2.
Posted for posterity…
insert into product_producers_movies (producer_id, movie_id)
(select p.id, m.id
FROM product_producers_list as p, product_movies as m WHERE p.name = '$producername' AND m.name = '$moviename')