views:

68

answers:

1

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 give 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 -

  1. find the list of all menus from menus table
  2. find the default value ov each element
  3. add row in menus_content table with that values

but maybe it is possible to do in one query?

Thanks

+1  A: 

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

Scott Saunders
i like this new type of queries( new, for me;)**Thanks**
Syom