Mysql 外键关联查询

SELECT * FROM user u WHERE EXISTS ( SELECT 1 FROM sale s where u.id = s.user_id);

该sql将返回有消费记录的用户信息,NOT EXISTS则相反,括号中的子查询将返回true和false,并不会返回具体信息 

猜你喜欢

转载自blog.csdn.net/DavidSoCool/article/details/82225742