我有两张桌子:Invoice
id number date client end client city vracht
1 4271 2014-5-28 ALLIN STIHO ZWOLLE 0和Materials。
id number material thickness length width amount price
1 14271 Ocoume 10 2500 1220 150 2,3
2 14271 Ocoume 15 2500 1220 60 2,3
3 14271 Ocoume 18 2500 1220 125 2,3
4 14271 Ocoume 22 2500 1220 44 2,3
5 14271 Ocoume 40 2150 1000 72 2,3
6 14271 Ocoume 18 3100 1530 25 2,3Invoice表中有发票。Materials表中有属于发票的材料。
我想要的是将具有相同发票号(表中的number列)的这些数据与select查询结合起来,如下所示:
number date client end client city vracht material thickness length width amount price
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 10 2500 1220 150 2,3
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 15 2500 1220 60 2,3
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 18 2500 1220 125 2,3
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 22 2500 1220 44 2,3
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 40 2150 1000 72 2,3
14271 2014-5-28 ALLIN STIHO ZWOLLE 0 Ocoume 18 3100 1530 25 2,3这个查询会是什么样子?
发布于 2014-12-03 09:25:09
select
`f`.`number`,
`f`.`client`,
`f`.`eind_client`,
`f`.`city`,
`f`.`vracht`,
`m`.`material`,
`m`.`thickness`,
`m`.`length`,
`m`.`width`,
`m`.`amount`,
`m`.`price`
from
`invoice` as `f`
right outer join
`materials` as `m`
on
`f`.`number`=`m`.`number`发布于 2014-12-03 09:21:23
select * from invoice, materials where invoice.number=materials.number建议将所需列写下来,而不是*。
发布于 2014-12-03 09:24:16
如前所述,如果您有一个外键关系,您可以使用JOIN.来给出所需的结果。
你可以用:
Select "columns you need " or "* "from invoice, materials
WHERE invoice.number = material.numberhttps://stackoverflow.com/questions/27267680
复制相似问题