SQL Query如果记录存在于多个表中则更新(SQL Query to update if record exist in multiple tables)

编程入门 行业动态 更新时间:2024-10-27 00:33:14
SQL Query如果记录存在于多个表中则更新(SQL Query to update if record exist in multiple tables)

我有四个MySQL数据库表:

成人; ///成人用品 孩子; ///儿童产品 宠物; ///宠物用品 首饰; ///珠宝产品

每个产品都有唯一的代码值。 我想在这4个表中进行搜索,如果在任何这些表中找到的代码更新其数量。 我应该使用什么?

我试过IF存在,但很难单独为初学者写它。 我也尝试谷歌这个解决方案,但没有找到任何搜索多个表和更新值的东西。

i have four MySQL database tables:

adults; /// adults products kids; /// kids products pets; /// pets products jewelry; /// jewelry products

Every product has a unique code value. I want to do search in these 4 tables and if code found in any of these tables update its quantity. What should I use?

I tried with IF exist but its quite hard to write it alone for beginner. I also tried to google for this solutions but didn't found anything for searching in multiple tables and updating values.

最满意答案

如果您可以根据现有设计的建议更新表设计,那么您可以使用Union all和if condition来解决您的问题。

这里的例子

select from ( select UCODE as UniqueCode from adults union all select UCODE from kids union all select UCODE from pets union all select UCODE from jewelry ) where UCODE = 'New_UCODE'

It would be efficient if you could update the table design as suggested for your existing design you could use Union all and if condition to solve your problem.

Here the example

select from ( select UCODE as UniqueCode from adults union all select UCODE from kids union all select UCODE from pets union all select UCODE from jewelry ) where UCODE = 'New_UCODE'

更多推荐

本文发布于:2023-08-07 22:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   则更   SQL   Query   update

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!