mysql - having trouble writing a query that list all salesmen that did not sell to a particular customer -
i successful in writing query lists salesmen did sell particular customer, not have not. suspect because same salesmen sold specific customer, sold other customers.
select a.name salesperson inner join orders b on a.salesperson_id = b.salesperson_id cust_id="4"; i thinking modifying same query trick:
.... a.salesperson_id <> b.salesperson_id cust_id="4"; but result lists salesmen. due fact same salesmen returned in original query, sold other customers
the 3 tables this:
salesperson table salesperson_id, name, age, salary 1 abe 61 140000 2 bob 34 44000 5 chris 34 40000 7 dan 41 52000 8 ken 57 115000 11 joe 38 38000 customer table cust_id, name, city industry type 4 faralon sacramento h 6 apple cupertino s 7 honda ny b 9 kolb oshkosh b orders table number, order_date, cust_id, salesperson_id, amount 10 8/2/1996 4 2 540 20 1/30/1999 4 8 1800 30 7/14/1995 9 1 460 40 1/29/1998 7 2 2400 50 2/3/1998 6 7 600 60 3/2/1998 6 7 720 70 5/6/1998 9 7 150 any appreciated. ~alpinehyker
you can this:
select a.name salesperson left join orders b on a.salesperson_id = b.salesperson_id , b.cust_id="4" b.number null so, salepersons, left join orders customer 4, , return rows there no such order.
i assuming number primary key orders, or @ least not null.
Comments
Post a Comment