group by and order by which one wil come fisrst

 $users = DB::table('users')

            ->groupBy('age')

            ->orderBy('age', 'desc')

            ->get();


In SQL, when using both the GROUP BY and ORDER BY clauses in a query, the GROUP BY clause is applied before the ORDER BY clause.

The order of the clauses in a SQL query is as follows:

  1. FROM: Specifies the table(s) from which to retrieve data.
  2. WHERE: Filters the data based on specific conditions.
  3. GROUP BY: Groups the rows based on one or more columns.
  4. HAVING: Filters the grouped data based on conditions.
  5. SELECT: Retrieves the columns or expressions to include in the result set.
  6. ORDER BY: Sorts the result set based on one or more columns.
  7. LIMIT: Specifies the number of rows to retrieve.


No comments:

Post a Comment

How to host application on server new way

 copy the htacess from public to root copy the server.php from public to root but rename to index.php htacess <IfModule mod_rewrite.c>...