i am trying to create a many to many relationship between 2 tables. ive got 3 tables for that. it follows TOXY model.
table a: a.id (primary key) table ab: ab.a_id (foreign key) ab.b_id (foreign key) table b: b.id (primary key)
how should i insert the data so it will be all linked up?
like this? "INSERT INTO a ('name') VALUES ('my name')";
then like this? "INSERT INTO b ('name') VALUES ('my name')";
but then i have to have the a.id and b.id to put it in table ab. how should i retrieve them?
i know i could do a SELECT a.id FROM a WHERE name = 'my name'. but isnt there an easier way for this that automatically returns an id when u INSERT the row?