Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql从多个表中选择_Mysql - Fatal编程技术网

mysql从多个表中选择

mysql从多个表中选择,mysql,Mysql,我有3个表,其值如下所示 **tbl_product** recID pID price colour 1 BDPLA-0001 1.23 White 2 BDPLA-0002 2.23 Black 3 BDPLA-0003 2.28 Blue tbl_product_size recID pID size stock

我有3个表,其值如下所示

**tbl_product**
recID      pID       price      colour
1         BDPLA-0001   1.23        White
2         BDPLA-0002   2.23        Black
3         BDPLA-0003   2.28        Blue

tbl_product_size
recID        pID       size       stock       
1            1         2.0cm       10 
2            1         3.0cm       20
3            2         2.5cm       30
4            3         3.6cm       40
5            3         3.8cm       50

tbl_order_details
recID       pID        quantity   size
201         BDPLA-0001   5        2.0cm 
202         BDPLA-0002   10       2.5cm

tbl_product = t
tbl_product_size = s
tbl_order_details = d

t.recID = s.pID
t.pID = d.pID
我如何组合表格并产生这样的结果

t.pID       s.size       s.stock     d.quantity  t.price
BDPLA-0001  2.0cm        10          5           1.23
BDPLA-0001  3.0cm        20          null        1.23
BDPLA-0002  2.5cm        30          10          2.23
BDPLA-0003  3.6cm        40          null        2.28
BDPLA-0003  3.8cm        50          null        2.28

您可以使用一个联合

select a,b,c from table A
union
select a,b,c from table B;

每个select中的列数和类型应相同。

您的问题似乎不完整,但您可以尝试以下操作,否则这将帮助您了解查询中如何使用多个表

select t.pID, s.size s.stock d.quantity t.price 
from  tbl_product t,  tbl_product_size s, tbl_order_details d 
where  t.recID=s.pID  and d.pID=t.pID
这样就行了

select t.pID, t.price, s.size, s.stock, d.quantity
from tbl_product t inner join tbl_product_size s on t.recID = s.pID
left outer join tbl_order_details d on t.pID = d.productCode and s.size = d.size;

尝试过的联盟不起作用…需要一些加入等。只是还不能理解逻辑。这将产生太多不相关的结果。基本上我希望tbl_订单_详细信息数据也与tbl_产品_大小合并。但是,我需要浏览tbl_产品,因为tbl_产品可以链接这两个表。