表a,id為1,2,3
表b,id為2,3,4
想找出不和b表id相等的數(shù)據(jù)。
(notin方法)
select * from a
where a.id not in (
select id from b
)
(leftjoin方法)
(1)
select * from a
left join b
on a.id=b.id
查出1,null ;2,2;3,3三條數(shù)據(jù)
上面sql加上where限制,where b.id=null, 就只剩下一條id=1的數(shù)據(jù)
UPDATE `取經(jīng)四人組`
SET ending='齊天大圣' WHERE `取經(jīng)四人組`.user_name in
(SELECT * FROM(SELECT `取經(jīng)四人組`.user_name
FROM `取經(jīng)四人組` INNER JOIN `孫悟空的朋友` ON `取經(jīng)四人組`.user_name = `孫悟空的朋友`.user_name )as temp)
SELECT
t1.id,
t1.NAME,
t2.num,
count( 1 ) cnt
FROM
tbl_goods t1
LEFT JOIN tbl_sale t2 ON t1.id = t2.goods_id
LEFT JOIN tbl_sale t3 ON t2.goods_id = t3.goods_id
WHERE
t2.num <= t3.num
GROUP BY
1,
2,
3
HAVING
cnt <= 2