MySQL不支持full join――怎么解决?
SELECT G.id,G.name,GG.goods_id,GG.img_url FROM sl_goods as G
LEFT JOIN sl_goods_gallery as GG on G.id=GG.goods_id
UNION ALL
SELECT G.id,G.name,GG.goods_id,GG.img_url FROM sl_goods as G
RIGHT JOIN sl_goods_gallery as GG on G.id=GG.goods_id
SELECT sl_goods.id,name,goods_id,img_url FROM sl_goods CROSS JOIN sl_goods_gallery
如何更新使用过滤条件中包括自身表?
-不知道具体说的索引值(id),泛型
-如题:将user1表中user_name与user2表中user_name相同的user1表的over替换成user2表中的over值?
然并卵MySQL是不能正确执行的
UPDATE user1 a JOIN
(SELECT b.user_name from user1 a INNER JOIN user2 b ON a.user_name=b.user_name) b ON a.user_name = b.user_name SET a.over=’齐天大圣’;
如题:需要将test.username=test1.name的test1.nickname赋值等于test.username+test.age
UPDATE test1 set nickname=CONCAT(test.username,test.age) where test.username=test1.name
失败,
test.username,test.age无通道提供,
在where后面没办法识其他表字段,除非用子查询&有准确值(id=1)
UPDATE test1 SET nickname=CONCAT(test.username,test.age)
WHERE test1.name IN
(SELECT t.username,t.age FROM test t INNER JOIN test1 t1 ON t.username=t1.name);
然并卵MySQL是不能正确执行的
UPDATE test1 t1 JOIN
(SELECT t.username,t.age FROM test t INNER JOIN test1 t1 ON t.username=t1.`name`) b
ON t1.`name`=b.username
SET t1.nickname=CONCAT(b.username,b.age)
成功,用join后面的[条件]查询内容提供给更新使用
适用于:需要限定条件含有别表字段且不能进行精确查询
含有别表字段:需要联表,子查询
不能进行精确查询:where处,子查询不管用&不能用;
本文出自 “DDD” 博客,转载请与作者联系!