->select
(
  'a.status as status',
  'b.name as customer_name', 
  'e.name as branch_name' , 
  'c.name as company_name',
  'd.name as project_name',
  'f.name as region_name',
  'e.code as branch_code',
  'e.id as branch_code',
  DB::raw('COUNT(a.id) as total_transaksi')
)
->groupBy
(
  'e.id',
  'b.name',
  'e.name', 
  'e.code',
  'a.status',
  'c.name',
  'd.name',
  'f.name'
)
            Asked
            
        
        
            Active
            
        
            Viewed 49 times
        
    0
            
            
         
    
    
        Thorsten Kettner
        
- 89,309
- 7
- 49
- 73
 
    
    
        muhammad syafiq
        
- 13
- 4
- 
                    check this https://stackoverflow.com/questions/1066453/mysql-group-by-and-order-by – Dimitris Papageorgiou May 30 '22 at 04:49
- 
                    This doesn't look like PHP or SQL. Google gives me Laravel for `DB::raw`, so I've added that tag. – Thorsten Kettner May 30 '22 at 04:55
- 
                    1What happens when you run this code? Do you get an error message or wrong results? If an error message: Which? If a wrong result: In which way wrong? – Thorsten Kettner May 30 '22 at 05:10
2 Answers
1
            It's incorrect, you can't use single name for same columns,
  'e.code as branch_code',
  'e.id as branch_code',
change to
  'e.code as branch_code',
  'e.id as branch_id',
 
    
    
        thisisnabi
        
- 1,045
- 9
- 21
- 
                    
- 
                    
- 
                    1No, don't; not all databases support it. Better to keep your SQL knowledge as widely applicable as possible rather than go down the "only mysql does this" rabbit hole – Caius Jard May 30 '22 at 06:39
- 
                    *you can't use single name* - [Databases don't care if you use same column aliases](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=f17b676df8139ad650774913dba80883) – Caius Jard May 30 '22 at 07:02
-1
            
            
        go to config/database.php
strict set false
 
    
    
        Mehrdad seyfi
        
- 9
- 1
- 
                    1This means something like "I rather want an incorrect result than getting an error message", correct? – Thorsten Kettner May 30 '22 at 05:08
-