INNER JOIN别名语法

时间:2014-10-01 21:32:57

标签: inner-join

我有这个

选择
              p.id,               p.name,               p.code,               clA.code为claCode,               sclA.code为sclaCode,               clB.code为clbCode,               sclB.code为sclbCode,               clC.code为clcCode,               sclC.code为sclcCode

FROM 
             products p
                 INNER JOIN catleathers clA
                    ON p.catleather_id_a = clA.id
                 INNER JOIN subcatleathers sclA
                    ON p.subcatleather_id_a = sclA.id
                 INNER JOIN catleathers clB
                    ON p.catleather_id_b = clB.id
                 INNER JOIN subcatleathers sclB
                    ON p.subcatleather_id_b = sclB.id
                 INNER JOIN catleathers clC
                    ON p.catleather_id_c = clC.id
                 INNER JOIN subcatleathers sclC
                   ON p.subcatleather_id_c = sclC.id

但我需要这样的东西

function getdatatableajaxcost()
   {

   $this->load->library('datatables');
   $this->datatables

    ->select("



            products.id as productid, 
            products.code as code, 
            products.name as name, 

            clA.code as claCode,
            sclA.code as sclaCode,
            clB.code as clbCode,
            sclB.code as sclbCode,
            clC.code as clcCode,
            sclC.code as sclcCode,

            products.details", FALSE)

            ->from('products')
            ->join('catleathers clA', 'products.catleather_id_a = clA.id', 'INNER')
            ->join('subcatleathers sclA', 'products.subcatleather_id_a = sclA.id', 'INNER')
             ->join('catleathers clB', 'products.catleather_id_a = clB.id', 'INNER')
            ->join('subcatleathers sclB', 'products.subcatleather_id_a = sclB.id', 'INNER')
            ->join('catleathers clC', 'products.catleather_id_a = clC.id', 'INNER')
            ->join('subcatleathers sclC', 'products.subcatleather_id_a = sclC.id', 'INNER')
            ->group_by("products.id");

          $this->datatables->unset_column('productid');
          $this->datatables->unset_column('image');

           echo $this->datatables->generate();

请帮忙!

1 个答案:

答案 0 :(得分:0)

解决! 谢谢大家!

 ->select("

            products.id as productid, 
            products.image as image, 
            products.code as code, 
            products.name as name, 
            categories.name as cname, 
            subcategories.name as subcategory, 
            products.cost, 
            products.price,  

            clA.code as claCode,
            sclA.code as sclaCode,
            clB.code as clbCode,
            sclB.code as sclbCode,
            clC.code as clcCode,
            sclC.code as sclcCode,

            catSoleA.code as catSoleACode,
            subcatSoleA.code as subcatSoleACode,

            catSoleB.code as catSoleBCode,
            subcatSoleB.code as subcatSoleBCode,

            catSoleC.code as catSoleCCode,
            subcatSoleC.code as subcatSoleCCode,

            products.details", FALSE)

            ->from('products')
            ->join('categories', 'products.category_id=categories.id', 'left')
            ->join('subcategories', 'products.subcategory_id=subcategories.id', 'left')

            ->join('catleathers clA', 'products.catleather_id_a = clA.id', 'INNER')
            ->join('subcatleathers sclA', 'products.subcatleather_id_a = sclA.id', 'INNER')

            ->join('catleathers clB', 'products.catleather_id_b = clB.id', 'INNER')
            ->join('subcatleathers sclB', 'products.subcatleather_id_b = sclB.id', 'INNER')

            ->join('catleathers clC', 'products.catleather_id_c = clC.id', 'INNER')
            ->join('subcatleathers sclC', 'products.subcatleather_id_c = sclC.id', 'INNER')

            ->join('catsoles catSoleA', 'products.catsole_id_a = catSoleA.id', 'INNER')
            ->join('subcatsoles subcatSoleA', 'products.subcatsole_id_a = subcatSoleA.id', 'INNER')

            ->join('catsoles catSoleB', 'products.catsole_id_b = catSoleB.id', 'INNER')
            ->join('subcatsoles subcatSoleB', 'products.subcatsole_id_b = subcatSoleB.id', 'INNER')

            ->join('catsoles catSoleC', 'products.catsole_id_c = catSoleC.id', 'INNER')
            ->join('subcatsoles subcatSoleC', 'products.subcatsole_id_c = subcatSoleC.id', 'INNER')


            ->group_by("products.id");