一个查询中包含很多内容。是否可以?

发布于 2024-09-07 20:36:49 字数 921 浏览 2 评论 0原文

我有三个表

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

第二个表存储有关菜单的数据(所有语言的名称),即。第二个表的 id_parent 是第一个表的 id。

假设我添加了一种新语言,id=4。现在我需要为所有菜单提供默认值(必须等于 id_lang = 1 值),因此我需要在 menus_data

| 中添加行--4----1------------menu_eng------4--------|

我必须对 菜单表。

我可以使用树查询来做到这一点 -

  1. menus 表中找到所有菜单的列表
  2. ,找到每个元素的默认值,
  3. menus_content 表中添加具有该值的行

,但也许是可以在一个查询中完成吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兰花执着 2024-09-14 20:36:52

我认为这是可能的。它会是这样的:

insert into `menus_data` select null, `id_parent`, `name`, 4 from `menus_data` where `id_lang` = 1;

我还没有检查过,所以语法可能有点不对。该查询还假设每个菜单的menus_data 中都有一条id_lang=1 的记录。

有关此类查询的更多信息,请参见:http://dev .mysql.com/doc/refman/5.1/en/insert-select.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文