How can you guarantee data is sorted as you wish?
Use an ORDER BY clause
SQL Server 70-461 03-02
Which of these two clauses are conceptually evaluated first and why is it important? ORDER BY or SELECT
SQL Server 70-461 03-02
What is the difference between a query with an ORDER BY clause and one without?
SQL Server 70-461 03-02
What order is assumed if you don’t indicate a direction for sorting?
Ascending
SQL Server 70-461 03-02
How do you specify order direction?
SQL Server 70-461 03-02
How can you specify more than one column to ORDER BY?
SQL Server 70-461 03-02
How can you sort by multiple columns and have different sort directions for each column?
SQL Server 70-461 03-02
What is the best way to refer to items you want to sort in the ORDER BY clause?
Refer to column names or expressions based on column names.
SQL Server 70-461 03-02
Can you order by a column that you are not returning in the query?
SQL Server 70-461 03-02
When using the DISTINCT clause, what is your ORDER BY list limited to?
ONLY elements that appear in the select list.
SQL Server 70-461 03-02
How are nulls treated when sorting?
SQL Server 70-461 03-02
What type of sort is considered bad practice? And why?
Why?
- It is not relational. Attributes in a table have no specific order where the table is relational.
- If you assign ordinal positions to expressions in a select list, what happens if the order of the select list changes and you forget to change the ORDER BY list?
SQL Server 70-461 03-02
How does indexing affect the ORDER BY clause?
If the column you are ordering by does not have an index, SQL Server may have to sort before addressing your ORDER BY request. This can affect query performance.
SQL Server 70-461 03-02
What happens if you try to order by a column that is not included in the select clause and the DISTINCT statement is used?
The query will fail. Say the query is asking for distinct cities and wants to order by birthdate of the employee cities. Since the query is only asking for one row per city and there could be multiple birthdates for different employees in the same city, instead of making an assumption as to which birthdate to use it just fails.
SQL Server 70-461 03-02
What is deterministic ordering?
SQL Server 70-461 03-02