我有四个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'更多推荐
发布评论