ryan ter ryan ter - 5 months ago 24
MySQL Question

forming a subquery inside mysql?

List the customer number, customer name, and sales rep that have the same rep number as customer number 282. This will need to be a subquery and do not test for sales rep 35 explicitly. Let MySQL do the work for you. Insert your query and results here.

use premier_products;

select customer.customer_num,customer.customer_name,rep.first_name
(SELECT rep_num
from rep,customer
where rep.rep_num = customer.rep_num
and customer_num = 282)
from customer,rep;

im confused with how to form a subquery with the following question. the only two fileds that are related between the two tables is rep.rep_num = customer.rep_num.


Answer Source

You need to study about tables Join in MySql.

Your query doesn't need a subquery:

SELECT customer.customer_num, customer.customer_name, rep.first_name, rep.rep_num
FROM rep
JOIN customer
ON rep.rep_num = customer.rep_num
WHERE customer_num = 282;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download