语法:select list from left_tab left|right outer join right_tab on join_condition [where keyword is null] #过滤满足条件的数据,保留不满足条件的数据 order by sort_columns;#哪些商品没有被客户购买过? SELECT* FROM ecs_goods; SELECT * FROM ecs_order_goods; SELECT DISTINCT g.goods_id, g.goods_name, g.shop_price,og.goods_id FROM ecs_goods g LEFT OUTER JOIN ecs_order_goods og ON g.goods_id = og.goods_id WHERE og.goods_id IS NULL;
#商品类型表中哪些商品类型没有出现在商品表中 SELECT gt.* FROM ecs_goods AS g RIGHT OUTER JOIN ecs_goods_type AS gt ON g.goods_type = gt.cat_id WHERE g.goods_type IS NULL;join嵌套 与内连接中的join嵌套用法类似. #找出没有购买过诺基亚E66商品的客户信息 SELECT * FROM ecs_users; SELECT * FROM ecs_order_info; SELECT * FROM ecs_order_goods; SELECT u.user_id,u.user_name,u.email FROM (ecs_order_goods og INNER JOIN ecs_order_info oi ON og.order_id = oi.order_id AND og.goods_name = '诺基亚E66') RIGHT OUTER JOIN ecs_users u ON oi.user_id = u.user_id WHERE oi.user_id IS NULL;