doubang9906 2015-11-05 16:12
浏览 31

在WHERE子句中加入第3个表

I'm trying to extend a 2 table join query to join 3 tables. I'm using PDO

SELECT tb.product, COUNT(tb.ID) AS nums FROM items tb LEFT JOIN itemCode cod ON tb.ID = cod.codeID WHERE tb.product = :product AND cod.name = :cName

The above 2 table join works. My question is, how do I match itemCode's availabilityID column to tblC's stockID column and add it to the WHERE clause with same query to get the result?

So basically I want to check if the availabilityID column of itemCode table match with stockID column of tblC table.

EDIT: table structure:

**items table**
ID   |  product 

**itemCode table** 
codeID   |  name 

**tblC table**
stockID
  • 写回答

1条回答 默认 最新

  • doudouwd2017 2015-11-05 16:21
    关注

    As stated in your question you want to match availabilityID with stockID, this is what the query does. However, the availabilityID does not show up in your edit.

    SELECT tb.product, COUNT(tb.ID) AS nums
    FROM items tb
    LEFT JOIN itemCode cod ON tb.ID = cod.codeID
    JOIN tblC stock ON stock.`stockID` = cod.`availabilityID`
    WHERE tb.product = :product AND cod.name = :cName
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services