天天看点

MySQL使用子查询

利用子查询进行过滤

SELECT * FROM orderitems WHERE prod_id = 'RGAN01';
SELECT * FROM orders WHERE order_num IN (20007,20008);
SELECT * FROM orders WHERE order_num IN (SELECT order_num FROM orderitems WHERE prod_id = 'RGAN01');
SELECT * FROM customers WHERE cust_id IN (1000000004,1000000005);
SELECT * FROM customers WHERE cust_id IN (SELECT cust_id FROM orders WHERE order_num IN (SELECT order_num FROM orderitems WHERE prod_id = 'RGAN01'));
           
MySQL使用子查询
MySQL使用子查询
MySQL使用子查询
MySQL使用子查询
MySQL使用子查询

继续阅读