sqlite多表加入......怎么样?

时间:2012-08-02 08:14:58

标签: sqlite join

我有三张桌子doodhiya,doodhdata和cashdata。

我正在尝试加入这些并通过此代码获取所需的数据但未成功

SELECT dname,ddate,dmonth,dyear,dmilk,uid 
FROM doodhiya
   INNER JOIN  doodhiya.dhid = doodhdata.ddhid
   INNER JOIN  doodhdata.dhid = cashdata.uid
WHERE (dname='$mik' AND dmonth='$mikdatem' AND dyear='$mikdatey')
ORDER BY  ddate ASC

我必须做什么?

3 个答案:

答案 0 :(得分:2)

您缺少联接中的表名和ON关键字

SELECT dname,ddate,dmonth,dyear,dmilk,uid 
FROM doodhiya
   INNER JOIN doodhdata ON doodhiya.dhid = doodhdata.ddhid
   INNER JOIN cashdata ON doodhdata.dhid = cashdata.uid
WHERE (dname='$mik' AND dmonth='$mikdatem' AND dyear='$mikdatey')
ORDER BY  ddate ASC

关于这部分问题的说明:

  

请告诉我我必须做的事情

手册中记录了连接的语法(以及Web中的数百万个SQL引用)。因此,下次您可以做的最好的事情是首先查阅手册和/或SQL参考。

答案 1 :(得分:-1)

SELECT retailername,
       productname,
       qty,
       stock,
       price,
       discount
FROM   temptablename,
       productmaster,
       retailermaster
WHERE  temptablename.pid = productmaster.productid
       AND temptablename.rid = retailermaster. retailercode 

答案 2 :(得分:-1)

SELECT dname,
      ddate,
      dmonth,
       dyear,
      dmilk,
      uid
FROM  doodhdata,
       cashdata
 WHERE  doodhiya.dhid = doodhdata.ddhid
       AND doodhdata.dhid = cashdata.uid
       AND dname='$mik' 
       AND dmonth='$mikdatem' 
      AND dyear='$mikdatey'
ORDER BY  ddate ASC