Sql statements executes in a logical processing order, or binding order, for a SELECT statement. This order determines when the objects defined in one step are made available to the clauses in subsequent steps.
For example, if the query processor can bind to (access) the tables or views defined in the FROM clause, these objects and their columns are made available to all subsequent steps. Conversely, because the SELECT clause is step 8, any column aliases or derived columns defined in that clause cannot be referenced by preceding clauses. However, they can be referenced by subsequent clauses such as the ORDER BY clause. The actual physical execution of the statement is determined by the query processor and the order may vary from this list.
- GROUP BY
- WITH CUBE or WITH ROLLUP
- ORDER BY
Let’s take an example: we have a table in our database
const val TABLE_NAME = "health_log"
and that contains a set of data which is the given json.
From the given table if we want to fetch entries for unique measurement_id, and for latest date.
because the order of execution for sql statement is groupBy, select and then selectBy. It will first remove duplicate entries and then sort them by date, which can remove latest date entries for same measureId.
This query will return you complete list in sort by date order. Then you can remove duplicate entries using any data structure.
For More detail you can visit HERE.
Thank you for reading. 👏 I really hope you’ve found this article helpful. Your claps are really appreciated to help others find this article 😃 .