How to sort rows with SQL: Databases for Developers #12

  Рет қаралды 6,729

The Magic of SQL

The Magic of SQL

Күн бұрын

Пікірлер: 12
@IncredibleAdventure1
@IncredibleAdventure1 3 ай бұрын
Hello Chris, I have one question regarding order by. Does Oracle Database sort results in ascending order based on the first column of the first query when using set operator Union implicitly(by default)?
@TheMagicofSQL
@TheMagicofSQL 3 ай бұрын
No. If you use UNION ALL the database just combines the data sets. If you use UNION it'll add a deduplication step. This *might* be implemented using a sort. A hash is more likely though.
@strielok1158
@strielok1158 Жыл бұрын
What about clustered indexes? If a table has such an index, select from that table will always return the records in the same order (of course if there is no order by clause), is that correct? As far as I know, in many RDBMS, the primary key index is going to be clustered by default.
@TheMagicofSQL
@TheMagicofSQL Жыл бұрын
The only way to GUARANTEE a query returns rows in particular order is by adding an ORDER BY to it. Even with a clustered table (only the default in SOME databases), the query may return rows in a different order. A common reason is because it uses a different index to access the data.
@SURESHRAJA-c5x
@SURESHRAJA-c5x 4 жыл бұрын
Hi bro , I am having a top n query , taking long time ... the reason I found is the columns I am using in order by having no index. Could you help me?
@TheMagicofSQL
@TheMagicofSQL 4 жыл бұрын
Sorting large tables can take a long time. Creating an index including columns in the where clause and sort can help. Filtering the data before the top-N so you process fewer rows should help too (if possible). If you're using Oracle Database and need more help, post details to asktom.oracle.com and we'll see if we can assist. Ensure you include your query and its execution plan.
@juno7893
@juno7893 6 жыл бұрын
Perfect
@TheMagicofSQL
@TheMagicofSQL 6 жыл бұрын
Thanks! :)
@grigorvardanyan
@grigorvardanyan 3 жыл бұрын
Really appreciate for the videos, but I believe they could've been a bit shorter
@TheMagicofSQL
@TheMagicofSQL 3 жыл бұрын
What would you cut?
@Ashishkumar-qo4jn
@Ashishkumar-qo4jn 5 жыл бұрын
Do not understand
@TheMagicofSQL
@TheMagicofSQL 5 жыл бұрын
What don't you understand? Please clarify!
Analytic Functions: Databases for Developers #13
5:42
The Magic of SQL
Рет қаралды 6 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
SQL Subqueries: Databases for Developers #11
7:45
The Magic of SQL
Рет қаралды 8 М.
The ORDER BY and LIMIT Clauses in SQL to Help With Sorting
3:08
Becoming a Data Scientist
Рет қаралды 21 М.
25 Sorting data in SQL Server
3:57
Learn SSIS
Рет қаралды 1,2 М.
Null: Databases for Developers #10
7:42
The Magic of SQL
Рет қаралды 11 М.
How to Read an Execution Plan: Databases for Developers: Performance #1
9:34
What are Optimizer Statistics? Databases for Developers: Performance #2
11:19
How to Find Slow SQL: Databases for Developers: Performance #9
11:16
The Magic of SQL
Рет қаралды 17 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН