In SQL, you can join three tables or more by adding another join after the first one.
You can also run nested joins by specifying one join as the join condition for another.
Continue readingIn SQL, you can join three tables or more by adding another join after the first one.
You can also run nested joins by specifying one join as the join condition for another.
Continue readingIf you ever find yourself in the situation where you’re about to execute a stored procedure, but you suddenly catch yourself. You wonder “How many columns does this thing return? Which tables? Does it query a remote server?”
The good news is there are several ways to get this information before you run the query. Let’s look at them.
Continue readingA LEFT SEMI JOIN
is kind of a half-join. It returns any distinct values that are returned by both the query on the left and right sides of the query.
However, when using T-SQL in SQL Server, if you try to explicitly use LEFT SEMI JOIN
in your query, you’ll probably get the following error:
A LEFT ANTI SEMI JOIN
is a type of join that returns only those distinct rows in the left rowset that have no matching row in the right rowset.
But when using T-SQL in SQL Server, if you try to explicitly use LEFT ANTI SEMI JOIN
in your query, you’ll probably get the following error:
In SQL, the UNION
clause concatenates the results of two queries into a single result set.
You can use the UNION
clause with or without the ALL
argument:
UNION ALL
– Includes duplicates.UNION
– Excludes duplicates.Some RDBMSs also accept UNION DISTINCT
, which is the equivalent to UNION
. That is, it excludes duplicates.
Below are some basic examples to demonstrate how it works.
Continue readingIn SQL, the AVG()
function is an aggregate function that returns the average of all values in a given expression.
It can also be used to return the average of all distinct (unique) values in an expression.
The expression must be numeric (it cannot be character string, bit string, or datetime).
Below are some basic examples to demonstrate how it works.
Continue readingIn SQL, the SUM()
function is an aggregate function that returns the sum of all values in a given expression.
It can also be used to return the sum of all distinct (unique) values in an expression.
The expression must be numeric (it cannot be character string, bit string, or datetime).
Below are some basic examples to demonstrate how it works.
Continue readingIn SQL, the MAX()
function is an aggregate function that returns the maximum value in a given expression.
Below are some basic examples to demonstrate how it works.
Continue readingIn SQL, the MIN()
function is an aggregate function that returns the minimum value in a given expression.
Below are some basic examples to demonstrate how it works.
Continue readingIn SQL, the COUNT()
function is an aggregate function that returns the number of items found in a group.
You can use COUNT()
in multiple parts of a query. For example, you can use it in the SELECT
list, or the HAVING
clause when filtering groups.