Questions tagged [subquery]
"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). The subquery's SELECT statement is always found within brackets/parenthesis.
subquery
11,404
questions
0
votes
1
answer
31
views
Combine SQL queries for output
I have two queries, where I need to get the ID from the first query and pass it to the second query.
How do I do this for all the ID's in the first query?
select id, name from [ignite].[COND] --> ...
0
votes
0
answers
29
views
Postgresql SELECT optimisation into Django ORM [closed]
Please see below a PostgreSQL SELECT statement. This presently returns around 300k rows, which is the grouped result of several million underlying rows. The dataset is only going to get larger. Using ...
1
vote
1
answer
44
views
Snowflake unsupported subquery type for UDTF
In Snowflake, I'm trying to save a large amount of code size and maintenance by creating a UDTF to show flags for each row v based on presence of rows in x or y meeting some pattern.
The error I get ...
0
votes
2
answers
46
views
Exclude rows where column matches another column without subquery
I have a result set of parent categories and subcategories. I want to exclude all parent categories if a subcategory exists in the results.
What I would do is using a NOT IN in the query, but that ...
-1
votes
1
answer
54
views
How to get a count of in a SQL subquery
I am working on the following SQL where I am getting a few values using a sub query; I need to get another value, but that has some different conditions:
SELECT Operator,
COUNT(*) AS 'Sales',
...
0
votes
0
answers
36
views
h2db: can I use parameterized WITH clauses (CTEs) in subqueries
I'm using h2db 2.2.224 as Test-DB in Spring Boot 3.2.5, running a JPA native query.
I have a WITH clause (CTE) that uses a query parameter. This WITH clause does not work in a subquery against h2db. ...
-2
votes
1
answer
33
views
need some explanation about MySQL where ... in ... subquery
Above is a given table of data and I need to get the result data like the one below.
SELECT ID
FROM
(
SELECT ID, PARENT_ID
FROM ECOLI_DATA
WHERE PARENT_ID IN (SELECT ID FROM ECOLI_DATA ...
-1
votes
1
answer
24
views
Redshift: Subquery not working, returns error
I am trying to return a list of tables that are not found in table A but are found in table B.
Select tab.table_name
from information_schema.tables tab
Where tab.table_name not in (Select tc....
0
votes
0
answers
44
views
Can I use REPLACE in a subquery in Snowflake?
I am trying to use a function that reads its string input parameter value from a table A and returns an output based on a match on a table B.
If the string in Table A contains a substring like a ...
0
votes
1
answer
57
views
INSERT INTO SELECT subquery that uses a udf so that it returns 1 value
I'm attempting to create a new table but altering some of the data from my old table using a INSERT INTO SELECT statement. I'm trying to take a field with numbers and letters and pull out the numbers ...
0
votes
2
answers
37
views
Select records not in subquery, returns nothing
I have a table with customers and another with documents, I want to get all customers that don't are in the subquery having document type 2
SELECT * from contactos
WHERE NOT EXISTS
(SELECT * from ...
0
votes
0
answers
24
views
get data from column of json arrays in sqlite table
I have SQLite table with columns like this:
id
info
1
[{"a": 1, "b":2}, {"a": 3, "b":4}]
2
[{"a": 5, "b":6}, {"a": 7, "b&...
2
votes
1
answer
50
views
Create nested queries with SQLAlchemy
I have a nested query that I need to write in a Pyhton project using SQLAlchemy, but everything I tried doesn't seem to work and I keep getting errors.
This is the SQL query (I'm using Snowflake) and ...
0
votes
1
answer
54
views
Create a rowID / identity column in a cross-join subquery
I have a table with some of the combinations of two ids. I need to create a unique id for each other combination. Since some combinations already exist, I can't just use an identifier column.
The ...
0
votes
3
answers
49
views
Filter rows in SQL query when a subquery returns null
I have a problem with subqueries. I'd like to select rows which contain a sum from a different table - so far no problem. However I'd like to filter for rows that don't have sum.
Example: Table1 has ...