forming a subquery inside mysql?

我的梦境 提交于 2020-01-03 06:40:13

问题


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.

AND REP.FIRST_NAME REFERS TO SALES REP...


回答1:


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;


来源:https://stackoverflow.com/questions/46381067/forming-a-subquery-inside-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!