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

sun dried potato procedure

  Sun-Dried Potato Chips Recipe  https://www.youtube.com/watch?v=e_PVvAU77Qs , recipe for potato sun dried chips 1) ist peel off the potato ...