The PIVOT function is very useful but not easily understood at first. I thank Itzik Ben-Gan, Dejan Sarka and Ron Talmage and their study guide Exam 70-461: Querying Microsoft SQL Server 2012 for the brilliant explanation. Here’s their example replicated here. Remember there are 3 columns used in PIVOT. The…
SQL Query Result Order
Every time an SQL query is run without the ORDER BY clause, the sort order of the results returned is not guaranteed. SQL Server decides which is the best order to return the query. This is based on factors like whether indexes are used or data fragmentation on the physical…
SQL Logical Query Processing Order
This probably applies more to beginners or people who have been using SQL for a while but have been wondering why sometimes the query works in a certain way and sometimes it didn’t. Before I read the book for the exam 70-461, I found it relatively easy to just plonk…
SQL and Relational Theory
Do you know the foundation of SQL? According to the book Querying Microsoft SQL Server 2012 Training Kit on the Microsoft label, T-SQL is a Microsoft flavour of the more standard ANSI and ISO version of SQL which is based on a branch of mathematics called Relational Model. Relational Model…