mysql - update joind table with new data -



mysql - update joind table with new data -

im staring working sql , find challenge.

i have 2 tables joined, in t1 address_id fk form address

t1

id(pk) | name | email | fax | address_id(fk) 01 | n1 | n2 | n3 | 0

table address

id(pk) | adress | country 0 | nd | nd

im trying add together info address table , update fk on t1 table key table new data

i trying didn't work

insert adress (adress, country,) values ("um","dois") update t1 bring together adress set t1.address_id = adress.id t1.id = 01:

i tried 2 or 3 sql queries didn't work.

how can this?

when add together new record table address want update table t1 key of new record table address.

try :

insert address (`address`, `country`) values ('um', 'dois') ; update t1 set t1.address_id = (select last_insert_id()) t1.id = 01;

take here explanations last_insert_id() : http://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id

mysql sql

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 -