Is it possible to join table as below in Laravel?












-1















how can I join two tables with multiple columns in laravel, somthing like the below query:



SELECT
*
FROM
tab1 AS e
INNER JOIN
tab2 AS v ON v.Case1 = e.Case1 and v.id = e.id;


I have searched in google but could not find any way.



This is the code I've tried so far:



DB::table('tab1 as e')
->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
->get();









share|improve this question

























  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 11:53











  • anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

    – Salman Zafar
    Nov 24 '18 at 12:11











  • I used query builder join function but it gives error

    – Alee Reza
    Nov 24 '18 at 13:07






  • 1





    laravel.com/docs/queries#joins: "Advanced Join Clauses"

    – Jonas Staudenmeir
    Nov 24 '18 at 18:14











  • Can you show the code you tried that gave you an error?

    – Ross Wilson
    Nov 24 '18 at 18:48
















-1















how can I join two tables with multiple columns in laravel, somthing like the below query:



SELECT
*
FROM
tab1 AS e
INNER JOIN
tab2 AS v ON v.Case1 = e.Case1 and v.id = e.id;


I have searched in google but could not find any way.



This is the code I've tried so far:



DB::table('tab1 as e')
->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
->get();









share|improve this question

























  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 11:53











  • anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

    – Salman Zafar
    Nov 24 '18 at 12:11











  • I used query builder join function but it gives error

    – Alee Reza
    Nov 24 '18 at 13:07






  • 1





    laravel.com/docs/queries#joins: "Advanced Join Clauses"

    – Jonas Staudenmeir
    Nov 24 '18 at 18:14











  • Can you show the code you tried that gave you an error?

    – Ross Wilson
    Nov 24 '18 at 18:48














-1












-1








-1


0






how can I join two tables with multiple columns in laravel, somthing like the below query:



SELECT
*
FROM
tab1 AS e
INNER JOIN
tab2 AS v ON v.Case1 = e.Case1 and v.id = e.id;


I have searched in google but could not find any way.



This is the code I've tried so far:



DB::table('tab1 as e')
->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
->get();









share|improve this question
















how can I join two tables with multiple columns in laravel, somthing like the below query:



SELECT
*
FROM
tab1 AS e
INNER JOIN
tab2 AS v ON v.Case1 = e.Case1 and v.id = e.id;


I have searched in google but could not find any way.



This is the code I've tried so far:



DB::table('tab1 as e')
->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
->get();






mysql laravel laravel-5.6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 1 '18 at 19:50









Jonas Staudenmeir

12.9k2934




12.9k2934










asked Nov 24 '18 at 11:27









Alee Reza Alee Reza

54




54













  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 11:53











  • anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

    – Salman Zafar
    Nov 24 '18 at 12:11











  • I used query builder join function but it gives error

    – Alee Reza
    Nov 24 '18 at 13:07






  • 1





    laravel.com/docs/queries#joins: "Advanced Join Clauses"

    – Jonas Staudenmeir
    Nov 24 '18 at 18:14











  • Can you show the code you tried that gave you an error?

    – Ross Wilson
    Nov 24 '18 at 18:48



















  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 11:53











  • anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

    – Salman Zafar
    Nov 24 '18 at 12:11











  • I used query builder join function but it gives error

    – Alee Reza
    Nov 24 '18 at 13:07






  • 1





    laravel.com/docs/queries#joins: "Advanced Join Clauses"

    – Jonas Staudenmeir
    Nov 24 '18 at 18:14











  • Can you show the code you tried that gave you an error?

    – Ross Wilson
    Nov 24 '18 at 18:48

















Have you tried anything?

– Shail Paras
Nov 24 '18 at 11:53





Have you tried anything?

– Shail Paras
Nov 24 '18 at 11:53













anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

– Salman Zafar
Nov 24 '18 at 12:11





anything is possible.. What have you tried so far? you can use the above query using Db::select('SELECT * FROM tab1 as e INNER JOIN tab2 as v ON v . Case1 = e . Case1 and v . id = e . id;');

– Salman Zafar
Nov 24 '18 at 12:11













I used query builder join function but it gives error

– Alee Reza
Nov 24 '18 at 13:07





I used query builder join function but it gives error

– Alee Reza
Nov 24 '18 at 13:07




1




1





laravel.com/docs/queries#joins: "Advanced Join Clauses"

– Jonas Staudenmeir
Nov 24 '18 at 18:14





laravel.com/docs/queries#joins: "Advanced Join Clauses"

– Jonas Staudenmeir
Nov 24 '18 at 18:14













Can you show the code you tried that gave you an error?

– Ross Wilson
Nov 24 '18 at 18:48





Can you show the code you tried that gave you an error?

– Ross Wilson
Nov 24 '18 at 18:48












2 Answers
2






active

oldest

votes


















0














Have you tried the following?



DB::table('tab1 as e')
->join('tab2 as v', function($join)
{
$join->on('v.Case1', '=', 'e.Case1');
$join->on('v.id','=', 'e.id');

})
->get();





share|improve this answer































    0














    This is how you have to go around it and it must work.
    Take this example of mine I did and it works



     $categ =  DB::connection('mysql')->table('SubCategories')
    ->leftJoin('Categories', 'Categories.id', '=', 'SubCategories.categories_id')
    ->select('SubCategories.id','SubCategories.Code','SubCategories.Name','SubCategories.Description','Categories.Name as CategoryName'
    )
    ->get();

    DB::connection('your connection from app.php file')table('tab1 as e')
    ->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
    ->Select('your select statement'),
    ->get();





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457659%2fis-it-possible-to-join-table-as-below-in-laravel%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Have you tried the following?



      DB::table('tab1 as e')
      ->join('tab2 as v', function($join)
      {
      $join->on('v.Case1', '=', 'e.Case1');
      $join->on('v.id','=', 'e.id');

      })
      ->get();





      share|improve this answer




























        0














        Have you tried the following?



        DB::table('tab1 as e')
        ->join('tab2 as v', function($join)
        {
        $join->on('v.Case1', '=', 'e.Case1');
        $join->on('v.id','=', 'e.id');

        })
        ->get();





        share|improve this answer


























          0












          0








          0







          Have you tried the following?



          DB::table('tab1 as e')
          ->join('tab2 as v', function($join)
          {
          $join->on('v.Case1', '=', 'e.Case1');
          $join->on('v.id','=', 'e.id');

          })
          ->get();





          share|improve this answer













          Have you tried the following?



          DB::table('tab1 as e')
          ->join('tab2 as v', function($join)
          {
          $join->on('v.Case1', '=', 'e.Case1');
          $join->on('v.id','=', 'e.id');

          })
          ->get();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 9:23









          Matt JamesonMatt Jameson

          474212




          474212

























              0














              This is how you have to go around it and it must work.
              Take this example of mine I did and it works



               $categ =  DB::connection('mysql')->table('SubCategories')
              ->leftJoin('Categories', 'Categories.id', '=', 'SubCategories.categories_id')
              ->select('SubCategories.id','SubCategories.Code','SubCategories.Name','SubCategories.Description','Categories.Name as CategoryName'
              )
              ->get();

              DB::connection('your connection from app.php file')table('tab1 as e')
              ->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
              ->Select('your select statement'),
              ->get();





              share|improve this answer




























                0














                This is how you have to go around it and it must work.
                Take this example of mine I did and it works



                 $categ =  DB::connection('mysql')->table('SubCategories')
                ->leftJoin('Categories', 'Categories.id', '=', 'SubCategories.categories_id')
                ->select('SubCategories.id','SubCategories.Code','SubCategories.Name','SubCategories.Description','Categories.Name as CategoryName'
                )
                ->get();

                DB::connection('your connection from app.php file')table('tab1 as e')
                ->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
                ->Select('your select statement'),
                ->get();





                share|improve this answer


























                  0












                  0








                  0







                  This is how you have to go around it and it must work.
                  Take this example of mine I did and it works



                   $categ =  DB::connection('mysql')->table('SubCategories')
                  ->leftJoin('Categories', 'Categories.id', '=', 'SubCategories.categories_id')
                  ->select('SubCategories.id','SubCategories.Code','SubCategories.Name','SubCategories.Description','Categories.Name as CategoryName'
                  )
                  ->get();

                  DB::connection('your connection from app.php file')table('tab1 as e')
                  ->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
                  ->Select('your select statement'),
                  ->get();





                  share|improve this answer













                  This is how you have to go around it and it must work.
                  Take this example of mine I did and it works



                   $categ =  DB::connection('mysql')->table('SubCategories')
                  ->leftJoin('Categories', 'Categories.id', '=', 'SubCategories.categories_id')
                  ->select('SubCategories.id','SubCategories.Code','SubCategories.Name','SubCategories.Description','Categories.Name as CategoryName'
                  )
                  ->get();

                  DB::connection('your connection from app.php file')table('tab1 as e')
                  ->join('tab2 as v', 'v.Case1', '=', 'e.Case1', 'and', 'v.id', '=', 'e.id')
                  ->Select('your select statement'),
                  ->get();






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 26 '18 at 9:27









                  lutakynlutakyn

                  7211




                  7211






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457659%2fis-it-possible-to-join-table-as-below-in-laravel%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Tonle Sap (See)

                      I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                      Guatemaltekische Davis-Cup-Mannschaft