数据库多表查询

  string strSql = "select e.MaterialEnterID,e.MaterialID,e.Num,e.EnterDate,p.ParentComName " +
                     "from t_MaterialEnter e left join t_ParentCompany p on e.ParentComID = p.ParentComID";

  string strSql = "select ml.MaterialLibID,p.ParentComName,m.MaterialName,m.MaterialType,ml.TotalNum " +
                            "from (t_MaterialLib ml left join t_ParentCompany p on ml.ParentComID = p.ParentComID) " +
                            "left join t_Material m on ml.MaterialID = m.MaterialID";

  string strSql = "select e.MaterialEnterID,p.ParentComName,m.MaterialName,m.MaterialType,prod.ProductName,prod.ProductType,e.Num,e.EnterDate " +
                            "from ((t_MaterialEnter e left join t_ParentCompany p on e.ParentComID = p.ParentComID) " +
                            "left join t_Material m on e.MaterialID = m.MaterialID) " +
                            "left join t_Product prod on e.ProductID = prod.ProductID";

注意:

(1)、left join on 关键字

(2)、空格

(3)、有的数据库产品需要括号,有的没必要

posted @ 2011-04-06 10:26  虚幻  阅读(214)  评论(0编辑  收藏  举报