如果上述子查詢的查詢結(jié)果不是一條,就不能成功執(zhí)行?[Err] 1242 - Subquery returns more than 1 row
2019-12-05
個人看法是鏈接的嵌套吧 或者子查詢外面套上連接,并對連接進(jìn)行更行。分析一下就是取經(jīng)四人組和兄弟組內(nèi)連接,得到孫悟空這個數(shù)據(jù),并把它當(dāng)作只有一條數(shù)據(jù)的數(shù)據(jù)表(個人覺得把這個表取個別名為C更好,更容易理解),再用A和這個數(shù)據(jù)表連接,對連接查詢道德數(shù)據(jù)進(jìn)行update操作。個人理解,歡迎指教!共勉!
2019-09-25
之前寫錯了, 這個才是我自己改的
-- 左外連接 取經(jīng)四人組中不是悟空的兄弟的人
SELECT DISTINCT a.`id`,a.`user_name`
FROM user_a AS a LEFT OUTER JOIN user_b AS b ON a.`user_name`=a.`user_name`
WHERE a.`user_name` NOT IN (SELECT user_name FROM user_b);
執(zhí)行結(jié)果是沒錯 意思也有的對上 但是總覺得有點繁瑣。
-- 左外連接 取經(jīng)四人組中不是悟空的兄弟的人
SELECT DISTINCT a.`id`,a.`user_name`
FROM user_a AS a LEFT OUTER JOIN user_b AS b ON a.`user_name`=a.`user_name`
WHERE a.`user_name` NOT IN (SELECT user_name FROM user_b);
執(zhí)行結(jié)果是沒錯 意思也有的對上 但是總覺得有點繁瑣。
2019-08-21
恕我直言一開始就應(yīng)該給個完整表結(jié)構(gòu),對照表,寫sql語句驗證效果才會更容易理解。大家只是希望可以更加易懂,我沒有說老師講得不好,只是有的細(xì)節(jié)需要注意一下。
因為不知道完整的表結(jié)構(gòu),我直接按照老師給的兩張表來建表,之后進(jìn)行左外連接的測試 發(fā)現(xiàn)結(jié)果是空,我就自己按理解改了一下SQL語句
-- 左外連接 取經(jīng)四人組中不是悟空的兄弟的人
SELECT DISTINCT a.`user_name`
FROM user_a AS a LEFT OUTER JOIN user_b AS b ON a.`user_name`=a.`user_name`
WHERE b.`user_name` IS NULL;
因為不知道完整的表結(jié)構(gòu),我直接按照老師給的兩張表來建表,之后進(jìn)行左外連接的測試 發(fā)現(xiàn)結(jié)果是空,我就自己按理解改了一下SQL語句
-- 左外連接 取經(jīng)四人組中不是悟空的兄弟的人
SELECT DISTINCT a.`user_name`
FROM user_a AS a LEFT OUTER JOIN user_b AS b ON a.`user_name`=a.`user_name`
WHERE b.`user_name` IS NULL;
2019-08-21
作為一個dba,我剛看到目錄時,覺得表與表直接的關(guān)聯(lián)還用講嗎,學(xué)完了才發(fā)現(xiàn),是我無知了。
2019-08-10
2. 優(yōu)化使用join 語句
select a.user_name , b.timestr , b.kills
from user1 a
join user_kills b on a.id = b.user_id
join user_kills c on c.user_id = b.user_id
group by a.user_name , b.timestr , b.kills
having b.kills = MAX(c.kills)
select a.user_name , b.timestr , b.kills
from user1 a
join user_kills b on a.id = b.user_id
join user_kills c on c.user_id = b.user_id
group by a.user_name , b.timestr , b.kills
having b.kills = MAX(c.kills)
2019-06-25
1. 使用子查詢語句:
select a.user_name,b.timestr,b.kills from user1 as a left join user_kills as b on a.id = b.user_id
where b.kills = (select max(c.kills) from user_kills as c where b.user_id = c.user_id);
select a.user_name,b.timestr,b.kills from user1 as a left join user_kills as b on a.id = b.user_id
where b.kills = (select max(c.kills) from user_kills as c where b.user_id = c.user_id);
2019-06-25
UPDATE user1,user2 set user1.over = '齊天大圣' WHERE user1.`user_name` = user2.`user_name`; 這樣也能操作
2019-05-03