在两个表之间传输一个值,其中一个字段是 %LIKE% 另一个
Transferring a value between two tables where one field is %LIKE% another
我正在尝试在 2 table 秒之间转移,其中一列与另一列 %LIKE%。
在 table "juice" 中,我有字段 title、brandid 和 id。
在 table "brands" 我有 id 和 title.
juice 中的标题字段将始终包含与品牌中的标题完全匹配的内容 - 以及一些其他字符串。
所以我正在尝试检查 brands.title 是否为 %LIKE% juice.title,如果是,则将 brands.id 放入 juice.brandid 字段。
这是我目前拥有的:
INSERT INTO juice(brandid)
SELECT id FROM brands
WHERE title LIKE CONCAT('%', @juice.title, '%')
听起来更像是您想要 UPDATE
而不是 INSERT
。看看
UPDATE juice
SET brandid = (SELECT brands.id
FROM brands
WHERE brands.title LIKE concat('%', juice.title, '%');
适合你。请注意,这需要 brands
中只有一行匹配。如果更多行匹配,您需要另外定义哪一行是正确的。
我正在尝试在 2 table 秒之间转移,其中一列与另一列 %LIKE%。
在 table "juice" 中,我有字段 title、brandid 和 id。
在 table "brands" 我有 id 和 title.
juice 中的标题字段将始终包含与品牌中的标题完全匹配的内容 - 以及一些其他字符串。
所以我正在尝试检查 brands.title 是否为 %LIKE% juice.title,如果是,则将 brands.id 放入 juice.brandid 字段。
这是我目前拥有的:
INSERT INTO juice(brandid)
SELECT id FROM brands
WHERE title LIKE CONCAT('%', @juice.title, '%')
听起来更像是您想要 UPDATE
而不是 INSERT
。看看
UPDATE juice
SET brandid = (SELECT brands.id
FROM brands
WHERE brands.title LIKE concat('%', juice.title, '%');
适合你。请注意,这需要 brands
中只有一行匹配。如果更多行匹配,您需要另外定义哪一行是正确的。