0

I am using mysql and my rows are as follows

name   type
Alex   Bank Tranfer     
Alex   Easy 
Alex   Sec  
Alex   Easy 
Alex   Bank Tranfer     
Alex   Sec  

I want the results to be like

Alex   Bank Tranfer     
Alex   Bank Tranfer 
Alex   Easy
Alex   Easy 
Alex   Sec  
Alex   Sec  

GROUP BY clause get the single distinct rows.

What could be the sql for it?

I am using laravel framework if anyone knows how to do it in laravel will be appreciated.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Alen
  • 1,221
  • 5
  • 21
  • 43
  • In sort use same columns as in group. group by firstName, lastName order by firstName, lastName – Alex K. Feb 25 '17 at 21:05

1 Answers1

0

The docs for Laravel query builder show only ordering by a single column:

$users = DB::table('NoOneNamesTheirTableInSQLQuestions')
                ->orderBy('name', 'asc')
                ->get();

But a quick search finds that you can repeat the orderBy() function to add more columns:

$users = DB::table('NoOneNamesTheirTableInSQLQuestions')
                ->orderBy('name', 'asc')
                ->orderBy('type', 'asc')
                ->get();
Community
  • 1
  • 1
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828