many things in one query. is it possible?
I have three tables
menus
+--id---ident---+
|--1----menu_1--|
menus_data
+--id---id_parent---name---------id_lang--+
|--1----1-----------menu_eng------1-------|
|--2----1-----------menu_rus------2-------|
+--3----1-----------menu_arm------3-------+
languages
+--id---name--------+
|--1----english-----|
|--2----russian-----|
|--3----armenian----|
second table store the data about menus (names in all languages), ie. id_parent of second table is id of first.
let's asume i add a new language, with id=4. now i need to gi开发者_JAVA技巧ve the default values( which must br equal to id_lang
= 1 value) to all menus, so i need to add row in menus_data
table
|--4----1-----------menu_eng------4-------|
and i must do it with all menus from menus
table.
I can do it with tree queries -
- find the list of all menus from
menus
table - find the default value ov each element
- add row in
menus_content
table with that values
but maybe it is possible to do in one query?
Thanks
I think it's possible. It would be something like this:
insert into `menus_data` select null, `id_parent`, `name`, 4 from `menus_data` where `id_lang` = 1;
I haven't checked that, so the syntax may be a little off. The query also assumes that there is a record for id_lang=1 in menus_data for every menu.
More info on this type of query here: http://dev.mysql.com/doc/refman/5.1/en/insert-select.html
精彩评论