替换INTERSECT以使用phpmyadmin

时间:2017-04-03 14:26:42

标签: mysql

我是SQL和phpmyadmin的新手,但在我的查询中我在交叉处有一个错误,我想知道如何更改它,所以它将打印我的表。

SELECT cust_code, cust_fname, cust_lname FROM lgcustomer join lginvoice         
USING (cust_code) WHERE employee_id = 83649

INTERSECT

SELECT cust_code, cust_fname, cust_lname FROM lgcustomer join lginvoice      
USING (cust_code) WHERE employee_id = 83677

ORDER BY cust_lname, cust_fname;

What it is suppose to look like

1 个答案:

答案 0 :(得分:0)

MySQL中没有

INTERSECT运算符。在这种情况下,您可以使用EXISTS

SELECT c1.cust_code, c1.cust_fname, c1.cust_lname 
FROM lgcustomer as c1
JOIN lginvoice         
USING (cust_code) 
WHERE employee_id = 83649 AND 
      EXISTS (SELECT 1
              FROM lgcustomer as c2
              join lginvoice      
              USING (cust_code) 
              WHERE employee_id = 83677 and 
                    c1.cust_code = c2.cust_code and 
                    c1.cust_fname = c2.cust_fname and 
                    c1.cust_lname = c2.cust_lname)