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

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...