2、当我们想要查询两个表的记录的时候,通常都会想到 left join。例:(select * from A left join B where A.account_id = B.account_id)
3、按分页来思考,我们只想要A表的记录,但是需要B表的一些字段作为搜索条件。如果查找到A表只有1条记录,B表有2条符合的记录,这样就会产生两条记录。例:(select * from A left join B where A.account_id = B.account_id where B.price = 55)
account_id
name
gender
age
book_id
account_id
book_name
price
1
小明
男
22
a
1
西游记
55
1
小明
男
22
b
1
红楼梦
55
解决(EXISTS)
select * from A where 1 and exists( select 1 from B where B.account_id = A.account_id and B.price = 55 )