deepu07
178
2
Laravel

Laravel query builder

Posted 7 months ago by deepu07

Hey folks, I'm stuck-up with query builder. I wanna merge duplicate column values into one row.

for example I have

id  name    age     rollnum
1   bob     24      null            
2   bob     24      1234

i wanna see 1 bob 24 1234. How can i do that in below query. Any help that would be appreciated. Thanks in advance.

`//Query Builder

    $data = \DB::table("table1 AS a")
      ->select("a.*")
      ->join(\DB::raw("(SELECT 
          id, name, age, COUNT(*),
          FROM table2
          GROUP BY b.name, b.age
          HAVING count(*) > 1
          ) as b"), function($join){
            $join->on("a.name", "=", "b.name")->on("a.age", "=", "b.age")->on("a.id", ">", "b.id");
      })
      ->orderBy("a.name")
      ->get();

`

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.