Top "Subquery" questions

"subquery" is vague SQL terminology, used to describe when there's either more than one `SELECT` statement in a query, or when used in Data Manipulation Language (DML) statements (IE: DELETE, UPDATE, INSERT, MERGE).

INSERT INTO with SubQuery MySQL

I have this Statement: INSERT INTO qa_costpriceslog (item_code, invoice_code, item_costprice) VALUES (1, 2, (SELECT item_costprice FROM qa_…

mysql insert subquery
SQLAlchemy - subquery in a WHERE clause

I've just recently started using SQLAlchemy and am still having trouble wrapping my head around some of the concepts. Boiled …

python sqlalchemy subquery
How can I treat a UNION query as a sub query

I have a set of tables that are logically one table split into pieces for performance reasons. I need to …

sql db2 subquery union
MySQL: Returning multiple columns from an in-line subquery

I'm creating an SQL statement that will return a month by month summary on sales. The summary will list some …

sql mysql subquery
Counting rows from a subquery

How could I count rows from a SELECT query as a value? Such as SELECT FUCNTIONIMLOOKINGFOR(SELECT * FROM anothertable) AS …

mysql sql subquery
SELECT with multiple subqueries to same table

I'm using the same SQL pattern over and over, and I know there has to be a better way, but …

sql sql-server tsql subquery
How to make a "distinct" join with MySQL

I have two MySQL tables (product and price history) that I would like to join: Product table: Id = int Name = …

mysql join distinct left-join subquery
SQL use column from subselect in where clause

I have a query that looks something like that: SELECT a, b, c, (SELECT d from B limit 0,1) as d …

mysql sql where-clause subquery
Hibernate Criteria Subquery

I need to do this SQL query with detachedCriteria: SELECT g.id FROM games g WHERE NOT EXISTS ( SELECT 1 FROM …

java hibernate subquery
Using subselect to accomplish LEFT JOIN

Is is possible to accomplish the equivalent of a LEFT JOIN with subselect where multiple columns are required. Here's what …

sql subquery multiple-columns