0

I'm fairly new to SQL and phpmyadmin, but in my query I have an error at intersect and I am wondering how to change that so it will print my table.

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

R Blanc
  • 27
  • 5

1 Answers1

1

INTERSECT operator is not available in MySQL. You can use EXISTS in this case:

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)    
Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98
  • When I use that code it prints out all the customers and not the customers between 83649 and 83677 – R Blanc Apr 03 '17 at 14:37
  • @RyanB I can't see how this could be possible. Can you please post some sample data so that I can reproduce the issue? – Giorgos Betsos Apr 03 '17 at 14:40
  • I put an image in my question on what it is suppose to look like. – R Blanc Apr 03 '17 at 14:42
  • @xDD Using the data posted I cannot reproduce the issue. Also, it is always preferable to post sample data in textual format, as, this way, it is easier to consume this data in order build a mock-up. – Giorgos Betsos Apr 03 '17 at 18:35