skip to Main Content

How can I write a query that will get the first active game_id that does not occur twice in the table below?

2

Answers


  1. Chosen as BEST ANSWER

    This will only show all the game id and the number of their occurences

    $user_info = DB::table('usermetas')
                     ->select('browser', DB::raw('count(*) as total'))
                     ->groupBy('browser')
                     ->get();
    

  2. How about :

    DB::table('tablename')
        ->select(DB::raw('COUNT(game_id) as totalgames, game_id'))
        ->where('is_active', 1)
        ->groupBy('game_id')
        ->havingRaw('COUNT(game_id) = 1')
        ->first();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search