This article provides an overview of the LEFT JOIN
in SQL, as well as some basic examples.
Tag: create query
SQL Inner Join
This article provides an overview of the INNER JOIN
in SQL, as well as some basic examples.
SQL Right Join
This article provides an overview of the RIGHT JOIN
in SQL, as well as some basic examples.
SQL Alias Explained
The SQL alias is a nice little feature of SQL that allows you to write more concise code and create column names when no column name exists.
There are two SQL alias types; column aliases, and table aliases. In this article, I provide an overview of both.
Continue readingHow to Write an ORDER BY Clause with Exceptions using SQL
In SQL, the ORDER BY
clause is commonly used to order the results of a query. It allows you to select one or more columns to order the results, and in most cases, it’s probably all you need.
But what if you need to make an exception?
What if you want the results to be ordered alphabetically, except for one row? Or several rows?
Or perhaps you simply want to put any NULL values to the end, while ordering the non-NULL results.
Either way, there’s a neat trick you can use that will enable you to do this. And the good part is, it’s simple.
You can cater for all of the above scenarios by adding a CASE
expression to your ORDER BY
clause.
How to Fix “Only one expression can be specified in the select list…” in SQL Server
In SQL Server, error message 116 occurs when you try to select multiple columns in a subquery without introducing it with the EXISTS
operator.
How to Return Duplicate Keys from a JSON Document in SQL Server
If you’re trying to extract values from a JSON document, but one or more of the values on the same level have duplicate keys, you might run into problems if you try to extract those values using JSON_QUERY()
or JSON_VALUE()
.
Both of those functions will only return the first value that matches the path.Â
Fortunately, there’s another option.
The OPENJSON()
function will return all values from any duplicate keys on the same level.
How to Select a Subset of Columns from a Stored Procedure’s Result Set (T-SQL)
Have you ever run a stored procedure, only to be overwhelmed at the number of columns returned? Maybe you only needed one or two columns, but it presented you with way too many columns for your needs on this particular occasion.
Fortunately, there’s a little trick you can use to retrieve selected columns from a stored procedure. This enables you to get just the columns you need.
And the best part is, it doesn’t involve having to create temporary tables and shuffling the data around.
All you need to do is pass your stored procedure to the OPENROWSET()
function.
The same concept can be applied to the OPENQUERY()
function.
How to View the Query Execution Plan in Azure Data Studio (SQL Server)
If you use Azure Data Studio for your database admin tasks, you might be wondering how you can view the execution plan for your queries?
Fortunately, this is easy!
You have the option of viewing:
- An estimated query execution plan
- The actual query execution plan
How EXCEPT Works in SQL Server
You can use the T-SQL EXCEPT
operator in SQL Server to return distinct rows from the left input query that aren’t output by the right input query.