Ever found yourself needing to update a bunch of rows in your database, but the condition for the update depends on data from another table? That’s where UPDATE
with a subquery comes in handy. Let’s break it down.
Tag: subqueries
SQL for Beginners: 10 Must-Know Concepts to Kickstart Your Database Journey
SQL stands for Structured Query Language. It’s the go-to query language for most of us who develop relational databases. If you want to work with relational database management systems, learning SQL is pretty much non-negotiable. Especially if you want to become a SQL developer.
If you’re interested in becoming a SQL developer, here are ten essential SQL concepts that you need to learn.
Continue readingUnderstanding the SQL Subquery
One of the things I love about SQL is just how easy it is to write a simple query that returns a meaningful result set, without having to a whole bunch of complex code. And I imagine most beginners are relieved when they discover this too.
However, while basic queries can go a long way, there’s a whole world of advanced techniques that can take our SQL development to another level. Somewhere in that world, would be the SQL subquery.
In this article, we look at the SQL subquery. We’ll explore what subqueries are, how they work, and when to use them. We’ll also look at some simple examples to demonstrate their use.
Continue readingCreate an Array from a Query in PostgreSQL
In PostgreSQL, an array constructor is an expression that builds an array value using values for its member elements.
One of the things we can do is build an array based on the results of a subquery.
Continue readingUnderstanding the ARRAY Constructor in PostgreSQL
In PostgreSQL we can create arrays with the ARRAY
constructor. An array constructor is an expression that builds an array value using values for its member elements.
Fix Msg 512 “Subquery returned more than 1 value” in SQL Server
If you get error Msg 512 that reads “Subquery returned more than 1 value…” in SQL Server, it’s because you’re using a subquery that returns more than one value in a scenario where this is not allowed.
Continue readingSQL SELECT for Beginners
The SELECT
statement is almost without doubt, the most commonly used statement in SQL.
The SELECT
statement is used for retrieving data from the database. You can specify which rows you want returned, and which columns.
SQL EXISTS Operator for Beginners
In SQL, the EXISTS
operator specifies a subquery to test for the existence of rows. It returns TRUE
when the subquery returns one or more rows.
A subquery is a query that is nested inside another query (or even another subquery)
This article contains some basic examples of the EXISTS
operator.
SQL IN Operator for Beginners
In SQL, the IN
operator allows you to filter your query results based a list of values.
You can also use it to match any value returned by a subquery (a subquery is a query that’s nested inside another query).
Continue reading