PHP / MYSQL - 一个查询中的多个表

时间:2022-10-05 03:39:36

I have 6 tables to display in one query. I'm trying three tables first but there's an error, and I don't know why. I want to show all fields, but I tried the first item code if going to work. Unfortunately, there's a bug.

我有6个表在一个查询中显示。我先尝试三张桌子,但是有一个错误,我不知道为什么。我想显示所有字段,但是如果要上班,我尝试了第一个项目代码。不幸的是,有一个错误。

The error is Warning: mysqli::query() [mysqli.query]: (21000/1242): Subquery returns more than 1 row in C:\wamp\www\DASMA\stockcard.php on line 541

错误是警告:mysqli :: query()[mysqli.query] :( 21000/1242):子查询在第541行的C:\ wamp \ www \ DASMA \ stockcard.php中返回多行

I want to display all the data in my all table whether one of it don't have data yet. Just without using SQL join.

我想在我的all表中显示所有数据,无论其中一个数据还没有数据。只是没有使用SQL连接。

   |allinvty3|(masterfile)
      ----------------
      |in_code       |
      |ecr_desc      |
      |pric_cash  
      |qty           |
      |ite_desc      |
      ---------------


 |(barcode, soldout_dm , dm_stock_transfer, adjustment etc. 
    -all have same fieldname)|
              ----------------
              |itemcode      |
              |qty           |
              |date  
              |qty           |
              |status        |
              ---------------
<?php
$sql = "
    SELECT  (
    SELECT itemcode as bcode
    FROM   barcode 
    ) ,
    ( 
    SELECT itemcode as bsold
    FROM   soldout_dm 
    ) ,
    (
    SELECT itemcode as  bstock
    FROM   dm_stock_transfer
    ) 
    ";
$result = $conn->query($sql);
?>

2 个解决方案

#1


0  

Try this

<?php

$sql = 'select b.itemcode as bcode, s.itemcode as bsold, d.itemcode as bstock from barcode as b, soldout_dm as s, dm_stock_transfer as d';

$result = $con->query($sql);

?>

#2


0  

$sql="select t1.column, t2.column,t3.column,t4.column,t5.column,t6.column from t1,t2,t3,t4,t5,t6 ";

this type of query will help you to get data from all six tables .

这种类型的查询将帮助您从所有六个表中获取数据。

#1


0  

Try this

<?php

$sql = 'select b.itemcode as bcode, s.itemcode as bsold, d.itemcode as bstock from barcode as b, soldout_dm as s, dm_stock_transfer as d';

$result = $con->query($sql);

?>

#2


0  

$sql="select t1.column, t2.column,t3.column,t4.column,t5.column,t6.column from t1,t2,t3,t4,t5,t6 ";

this type of query will help you to get data from all six tables .

这种类型的查询将帮助您从所有六个表中获取数据。