如何解决Mysql子查询

时间:2014-06-05 07:17:08

标签: mysql

这是一个问题

select stockrequest.clientnum, requestlist.productnum,requestlist.qtyrequest
from stockrequest, requestlist 
where stockrequest.requestnum = requestlist.requestnum

此查询将结果

client num   productnum    qty
1            123            4
2            345            5
3            456            7


select client.clientname, stockrequest.clientnum
from client , stockrequest
where stockrequest.clientnum = client.clientnum

clientname   clientnum
yd              1
myer            2
nike            3

我需要一个子查询,在第一个查询中将clientnum替换为client name

2 个答案:

答案 0 :(得分:1)

进行三方联接:

SELECT c.clientname, rl.productnum, rl.qty
FROM stockrequest AS sr
JOIN client AS c ON c.clientnum = sr.clientnum
JOIN requestlist AS rl ON rl.requestnum = sr.requestnum

答案 1 :(得分:0)

你可以选择全部:)(未经测试)

select s.clientnum, r.productnum, r.qtyrequest, c.clientname
from stockrequest s, requestlist r, client c
where s.requestnum = r.requestnum