首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL联合与MySQL内部连接结合

问MySQL联合与MySQL内部连接结合
EN

Stack Overflow用户
提问于 2016-06-20 05:14:53
回答 1查看 609关注 0票数 1

我想从allinventory_tb得到描述和模型。

所以我做了内部连接,但是当我要显示描述和模型的时候。

错误是:

注意:未定义索引:描述,注意:未定义索引:模型。

有什么建议吗?

代码语言:javascript
复制
  |allinventory_tb|
  ----------------
  |in_code        |
  |description    |
  |model          |
  ---------------
    $sql = "select t.itemcode  as itemcode ,sum(t.qty) as qty
    from ( 
    select itemcode,qty  from barcode INNER JOIN allinventory_tb on barcode.itemcode = allinventory_tb.in_code
    union all
    select itemcode,qty from adjustment_tb INNER JOIN allinventory_tb on adjustment_tb.itemcode = allinventory_tb.in_code where adjustment_tb.status='APPROVED'
    union all
    select itemcode,(qty * -1) from soldout_pd INNER JOIN allinventory_tb on soldout_pd.itemcode = allinventory_tb.in_code) as t
    group by itemcode";

    $result = $conn->query($sql);
EN

回答 1

Stack Overflow用户

发布于 2016-06-20 05:45:12

和您的查询,即

代码语言:javascript
复制
$sql = "select t.itemcode  as itemcode ,sum(t.qty) as qty
    from ( 
    select itemcode,qty  from barcode INNER JOIN allinventory_tb on barcode.itemcode = allinventory_tb.in_code
    union all
    select itemcode,qty from adjustment_tb INNER JOIN allinventory_tb on adjustment_tb.itemcode = allinventory_tb.in_code where adjustment_tb.status='APPROVED'
    union all
    select itemcode,(qty * -1) from soldout_pd INNER JOIN allinventory_tb on soldout_pd.itemcode = allinventory_tb.in_code) as t
    group by itemcode";


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

您将无法访问description和model列值,因为您没有在查询中指定Re欲列名,所以当您尝试在PHP中访问查询结果时,您将得到如下通知错误:

注意:未定义索引:描述,注意:未定义索引:模型。

尝试这个查询

代码语言:javascript
复制
$sql = "select description,model,t.itemcode  as itemcode ,sum(t.qty) as qty
    from ( 
    select description,model,itemcode,qty  from barcode as bc INNER JOIN allinventory_tb as ait on bc.itemcode = ait.in_code
    union all
    select description,model,itemcode,qty from adjustment_tb as adt INNER JOIN allinventory_tb as ait1 on adt.itemcode = ait1.in_code where adjustment_tb.status='APPROVED'
    union all
    select description,model,itemcode,(qty * -1) from soldout_pd as slp INNER JOIN allinventory_tb as ait2 on slp.itemcode = ait2.in_code) as t
    group by itemcode";


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

希望这对你有用..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37915015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档