将值从 A 表插入到 A 表 [英] Insert values from A table to A table

查看:32
本文介绍了将值从 A 表插入到 A 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 mysql 中有一张表用于存储菜单项.结构如下

I have one table in mysql that stores menu items. Structure is as below

表格:menu_list_hed

id    menu_name    shop_id    menu category
--------------------------------------------
 1     Breakfast      12          Veg
 2     Dinner         12          Veg
 .... Many more

现在,我有另一家有相同菜单但shop_id(13) 不同的商店.如何再次复制相同的值并使表格如下所示

Now, i have another shop which has same menu but shop_id(13) is different. How can i copy same values again and make table look like as below

id    menu_name    shop_id    menu category
--------------------------------------------
 1     Breakfast      12          Veg
 2     Dinner         12          Veg
 .... Many more
 25    Breakfast      13          Veg
 26    Dinner         13          Veg
 .... Many more

我尝试从 phpmyadmin 导出 SQL,但这需要很多时间,因为我必须手动更改每个 SQL 语句的 shop_id.

I tried exporting SQL from phpmyadmin but that will take lots of time as i have to manually change the shop_id for each SQL statement.

推荐答案

您可以使用 insert 和 select 并在 select 语句中提供您的 shop_id

You can use insert with select and provide your shop_id in select statement

INSERT INTO menu_list_hed
    (`menu_name`, `shop_id`, `menu category`)
select `menu_name`, '13' AS `shop_id`, `menu category`
from menu_list_hed where shop_id = 12
;

演示

这篇关于将值从 A 表插入到 A 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆