2017-04-03 69 views
0

我對SQL和phpmyadmin相當陌生,但在我的查詢中,我在相交處出現錯誤,並且想知道如何更改它以便打印我的表。將INTERSECT替換爲使用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

+0

可能是你http://stackoverflow.com/questions/2300322/intersect-in-mysql –

回答

0

INTERSECT運營商不可用在MySQL。您可以使用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)  
+0

當我使用該代碼它打印出所有的客戶這一個幫助,而不是83649和83677之間的客戶 –

+0

@RyanB我看不出這是怎麼可能的。您可以請張貼一些示例數據,以便我可以重現此問題嗎? –

+0

我在我的問題中放置了一個圖像,看看它是什麼樣的。 –