与table2连接后的mysql phpadmin update table1列,其中搜索特定的字段名称

时间:2021-09-13 16:38:10

This is my first post and I apologize that the title is mess. If someone can suggest a better one, I'll update it accordingly.

这是我的第一篇文章,我很抱歉标题很乱。如果有人可以提出更好的建议,我会相应更新。

My experience with sql is extremely small. The few queries I've put together have come from the little knowledge I have from coding in high school and a lot of google searching. Then I then splice things together and look like what I might need. Sometimes it works and sometimes it doesn't. Below is a query that I got working but I'm trying to expand on it to make it easier.

我对sql的经验非常小。我汇总的几个问题来自于我在高中编码和大量谷歌搜索方面的一点点知识。然后我将事物拼接在一起,看起来像我可能需要的东西。有时候它有效,有时却没有。下面是我开始工作的查询,但我正在尝试扩展它以使其更容易。

UPDATE `Database`.`products` 
SET `clearance` = 'Y', `products_order_date` = 'ENTER DATE HERE'

WHERE products_id IN (51604,51603,49209,49208,49207,45222,45220)

产品_id IN(51604,51603,49209,49208,49207,45222,45220)

The part I'm trying to make easier on myself is having to enter every product ID for this particular update. I would rather use LIKE %% instead of IN but there is not a column in 'products' that I can use. However, there is a table called 'products_description' which also has a column called 'products_id'. This table has a column called 'products_name'. If I could search by products_name, it would make my work easier.

我试图让自己更容易的部分是必须输入此特定更新的每个产品ID。我宁愿使用LIKE %%而不是IN,但我可以使用“产品”中没有列。但是,有一个名为'products_description'的表,它还有一个名为'products_id'的列。该表有一个名为'products_name'的列。如果我可以通过products_name进行搜索,那将使我的工作更轻松。

A crude example of what I need is

我需要的一个粗略的例子是

UPDATE `Database`.`products` 
SET `clearance` = 'Y', `products_order_date` = 'ENTER DATE HERE'
JOIN THE 2 TABLES SOMEHOW
WHERE `products_name` LIKE %WHATEVER%

I really hope this makes sense, if not please let me know.

我真的希望这是有道理的,如果不是,请告诉我。

Ideally, I would love to have the products_name column, which is currently in the products_description table, copied to the first table and have it match up with the products_id so then I wouldn't need to do this join thing. But of course I do not know how to do that either.

理想情况下,我希望将products_name列(当前在products_description表中)复制到第一个表并使其与products_id匹配,这样我就不需要执行此连接操作了。但我当然不知道该怎么做。

Hope someone can assist.

希望有人能提供帮助。

Thank you for your time.

感谢您的时间。

1 个解决方案

#1


0  

UPDATE 
    `handbags_jnh`.`products` as p join `products_description` as pd on p.products_id = pd.products_id 
SET 
    clearance = 'Y', products_order_date = 'ENTER DATE HERE' 
WHERE 
    products_nam`e LIKE %WHATEVER%

#1


0  

UPDATE 
    `handbags_jnh`.`products` as p join `products_description` as pd on p.products_id = pd.products_id 
SET 
    clearance = 'Y', products_order_date = 'ENTER DATE HERE' 
WHERE 
    products_nam`e LIKE %WHATEVER%