stored procedures - Mysql insert while selecting -



stored procedures - Mysql insert while selecting -

i have table words: id; name

1-dog 2-log 3-for

then have table characters: id; name

1-_og 2-_or 3-_ot

now have thirth relational table (lets phone call words_and_characters) want set ids table words , id table characters "match". table id composed id, word_id, character_id

in illustration above, table words_and_characters should contain following:

1-1-1 (the match "dog" , "_og") 2-2-1 (the match "log" , "_og") 3-3-2 (the match "for" , "_or")

i begun writing stored procedure first cursor iteratin through table characters according this:

select id, name characters;

and putting date way:

fetch curs1 i,n;

now, in each iteration, wanted like:

select * words name n;

well, im afraid little bit ineffective, if there lot of data. there improve way think? maybe avoid writing stored procedure , have kind of advances sql insert?

use join:

insert words_and_characters (word_id, character_id) select w.id, c.id words w bring together characters c on w.name c.name

mysql stored-procedures

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -