You have following tables
| Salesperson | Customer | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| Orders | ||||||||||||||||||||||||||||||||||||||||
|
Given the tables above, find the following:
a. The names of all salespeople that have an order with Samsonic.
a. The names of all salespeople that have an order with Samsonic.
solution:
SELECT distinct name FROM `salesperson` WHERE id in(select salesperson_id from customer,orders where id=cust_id AND name='Samsonic');
if you write above query like:
SELECT distinct name FROM `salesperson` WHERE id=(select salesperson_id from customer,orders where id=cust_id AND name='Samsonic');
It is invalid query because subquery returning multiple records so it can't be compared.
SELECT distinct name FROM `salesperson` WHERE id=(select salesperson_id from customer,orders where id=cust_id AND name='Samsonic');
It is invalid query because subquery returning multiple records so it can't be compared.
No comments:
Post a Comment