gpt4 book ai didi

mysql - 如何减少查询次数

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:27 25 4
gpt4 key购买 nike

我正在尝试生成一个 catalog 表,这样每次我添加到其他 2 个表时,它都将是相同的 id。目前,我必须运行多个查询才能生成。只想尝试简化它。这是我的原始查询,欢迎任何合并想法!

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = '32g bins')
where item_name = '32g bins';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Collection Bags')
where item_name = 'Collection Bags';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Chicken Wire Bins')
where item_name = 'Chicken Wire Bins';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = '5 gallon buckets')
where item_name = '5 gallon buckets';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Spray Paint')
where item_name = 'Spray Paint';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Open Sign')
where item_name = 'Open Sign';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Pricing Sign')
where item_name = 'Pricing Sign';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Calrecycle Sign')
where item_name = 'Calrecycle Sign';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Water Dispenser')
where item_name = 'Water Dispenser';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Water Bottles')
where item_name = 'Water Bottles';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Safe')
where item_name = 'Safe';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Security System')
where item_name = 'Security System';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Hand Sanitizer')
where item_name = 'Hand Sanitizer';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Working Gloves')
where item_name = 'Working Gloves';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Cleaning Gloves')
where item_name = 'Cleaning Gloves';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Ear Plugs')
where item_name = 'Ear Plugs';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Safety Goggles')
where item_name = 'Safety Goggles';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Office Desk')
where item_name = 'Office Desk';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Change/Cash Deposit Bags')
where item_name = 'Change/Cash Deposit Bags';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Laptop')
where item_name = 'Laptop';

update equipment_needed
set `catalog_id` = (select `id` from equipment_catalog where item_name = 'Writing Pens')
where item_name = 'Writing Pens'

;

最佳答案

尝试这样的事情:

update equipment_needed as t1
set `catalog_id` = (select `id`
from equipment_catalog as t2
where t2.item_name = t1.item_name)

关于mysql - 如何减少查询次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29598701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com