699
questions
1
vote
1
answer
56
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
3
answers
62
views
SQL Oracle - SUBQUERY to selectively pull data from *different* column, depending on table conditions
Jumping straight in. We have tables (TABLE) and audit tables (AUDITTABLE) that store changes to the main table.
In the table, we have entries like:
ID
Name
Created
LocationID
PersonID
1
Utah
01/01/...
0
votes
2
answers
56
views
BigQuery - #standardSQL giving error for Correlated Subqueries
I have two tables like:
table_1 table_2
ID CODE ID CODE
aa r qq r
aa k ff k
aa s aa r
bb r aa k
bb k aa s
cc r ...
0
votes
1
answer
144
views
ERROR: This type of correlated subquery pattern is not supported yet
I have a subquery that runs without problems on MySQL and I wanted to use the same query on AWS-Redshift, but I am getting this error: [0A000] ERROR: This type of correlated subquery pattern is not ...
0
votes
0
answers
76
views
Snowflake UDF sub query erorr
I have rewritten the below (orginal query) in many diferent ways but still cant seem to get it to work, same error occurs.
Snowflake CTE calling a function where a column value from the CTE is a ...
0
votes
1
answer
109
views
Is this a correlated subquery? If so, would a join be more efficient? [duplicate]
I have looked at this question and its answer but am still uncertain. My simplified schema is:
CREATE TABLE department(
ident text not null primary key,
name text ...
-1
votes
1
answer
114
views
Why is this SQL query valid? [duplicate]
Why doesn't this SQL query return ar error (in Oracle)?
field_99 exists only in table_1!
SELECT *
FROM table_1
WHERE table_1.field_1 IN
(SELECT table_2.field_1
FROM table_2
...
3
votes
0
answers
103
views
Weird working of correlated query - Is this SQL correct?
Please check the below query:
with sd as
(
select 1 id, 'abc' col from dual
union
select 2 id, 'xyz' col from dual
union
select 3 id, 'pqr' col from dual
),
t as
(
select 1 ...
-1
votes
2
answers
100
views
Should I use NOT IN or NOT EXISTS when UPDATING DATA
sql
UPDATE PERSON
SET ENROLMENT_DATE = CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT * FROM FEE_PAYMENT WHERE FEE_PAYMENT.PERSON_ID = PERSON.PERSON_ID);
UPDATE PERSON
SET ENROLMENT_DATE = ...
1
vote
1
answer
67
views
SQL to filter the data from inner query based on 2 conditions
I have the following table named TableB:
Datetime
Partid
2022-12-24T15:20:00.782Z
Part-A
2022-12-24T15:21:00.782Z
Part-B
2022-12-24T15:22:00.782Z
Part-B
2022-12-24T15:23:00.782Z
Part-A
2022-12-...
0
votes
1
answer
31
views
Unable to Aggregate Results From Query Containing Correlated SubQuery without Timeout - mysql 5.7
My initial query below runs fairly quickly around 9s and returns about 250K records. I want to group the results by month_year with a count of IDs, however, any attempt to group the results by a date, ...
0
votes
2
answers
458
views
How to alter column to VARCHAR type with length L where L is based on the column aggregation like MAX(LENGTH(column)), PostgreSQL DB?
I am trying to alter column named names type from text to VARCHAR with length L. Where L is the maximum length of the names. I am trying with inner/sub-query as follows:
Is this even possible? Any ...
0
votes
2
answers
30
views
Correlated Subquery appears to use circular logic
I googled correlated subquery, and it gave me the below example. However, it appears in the outer query, that department id will be determined by a dynamic salary, which in turn, is determined by a ...
0
votes
1
answer
93
views
Alternative for the below update with correlated sub query in Snowflake
In process of converting the Oracle code to Snowflake, got stuck on the below, any alternate approach for it on the Snowflake side would be appreciated
update trgt_tbl T
set (
T.cur_indicator,
T....
0
votes
1
answer
87
views
MariadB: using correlated subquery gives only one row
I have two tables c0 and m0 which I merge using a left join. The result is a table with 13 rows. I would like to add the first date of the next 40 days windows. Here are the data:
DROP TABLE IF EXISTS ...
0
votes
4
answers
5k
views
Get second highest salary in SQL
Getting Connection Lost in coorelated queries.
select emp_no,salary
from salaries e
where 2 =
(select count(distinct salary) from salaries p where p.salary>e.salary);
I tried this to get ...
0
votes
2
answers
103
views
Oracle - Make a correlated query more efficient
Oracle RDBMS :18C
This topic is subsequent to my previous thread:
Oracle - Where clause having null value condition does not give corresponding result
Because the last question is solved (to obtain ...
0
votes
0
answers
70
views
MySQL INNER JOIN subquery select one row from second table
I am trying to merge two separate queries that work into one query that would also work.
I have several tables and need some data from all of them.
I have a table of tasks (this is just the tasks ...
0
votes
2
answers
30
views
SELECT an additional column from another table based on a value between 2 other values
I have 2 pretty basic tables:
Table: user
id|name|exp
1|test|270
2|foo |510
Table: level
level|exp
1|0
2|100
3|250
4|500
I want to have a pretty simple query, which gives me my ...
2
votes
1
answer
147
views
Window function in scalar subquery does not work as expect
The following query can be used to calculate cumulative sums:
select
(select sum(c) over (ROWS UNBOUNDED PRECEDING) as a),
sum(c) over (ROWS UNBOUNDED PRECEDING ) as b
from (select unnest(ARRAY[...
0
votes
1
answer
184
views
Sql alchemy correlated subquery
class Person(Base):
__tablename__ = "stanovnik"
id = Column(Integer, primary_key=True)
ime = Column(String(20))
prezime = Column(String(50))
nadimak=Column(String(50),...
0
votes
2
answers
144
views
Unsupported correlated query redshift for case when exists
I'm running a case when exists to try to filter out anamoly data from my table, but I am running into a unsupported correlated query error.
I have a table of anomalies for different metrics and I want ...
0
votes
0
answers
60
views
BigQuery subQueries with join
I'm using bigQuery i have a table a with column details which is an array of data i want to select this array and every element in this array get an object name from another table: I have use this ...
-1
votes
1
answer
141
views
How to include correlated subquery clause in SQL Join?
So I'm trying to write a query that includes an IN clause within a join. The reason is because I need to join DLGVRSN to itself, and when the first one's DLGVRSN.DSTATUS = 500 then I need it to get ...
0
votes
1
answer
132
views
SQLite merge/union/flatten subqueries
I'm trying to write some SQL code in the same vein as the "Outlandish Recursive Query" examples at https://www.sqlite.org/lang_with.html.
In particular, I'm trying to make a prime sieve ...
1
vote
1
answer
171
views
MySQL doest not use indexes on subquery (exists)
why does MySQL not use the (expected) indexes when I query with a subquery (exists)?
I also tried it with an JOIN but happens the same, that MySQL does not use the indexes.
How can I improve this?
...
0
votes
0
answers
71
views
Correlated subquery in WHERE clause
Could someone help me with Correlated subquery in WHERE NOT EXISTS clause using below example of exercise, cause I am not sure how to write this subquery and how would this work in INGRES database.
...
0
votes
2
answers
36
views
mysql subselect on group by
I have a table of locations
CREATE TABLE `asset_location_rel` (
`a_id` int(11) NOT NULL,
`asset_id` int(11) NOT NULL,
`location_id` int(11) NOT NULL,
`deleted` int(11) NOT NULL DEFAULT 0,
`...
0
votes
2
answers
779
views
Insert data into table from another table based on non matching column values
I have two tables. Staging table refreshes every day and replaces LoadDate column with today's date. This data gets inserted into Final table where I want to insert just the new data.
Staging table:
...
1
vote
1
answer
17
views
Remove Correalted Subquery with Not Equal Join
SELECT
(SELECT COUNT(0)
FROM TestTable s_t
WHERE s_t.Test_type_id <> t.Test_type_id
) AS count
FROM
TestTable t
This is taking time eventhough index exists on table.
Help needed in removing ...
-1
votes
1
answer
106
views
MYSQL error code: 1054 Unknown column in where clause. Error occurring in Nested SubQueries
I am trying to get through a problem where there are multiple accounts of same scheme on same customer id. On a given txn date I want to retrieve the total Sanctioned Limit and total utilized amount ...
0
votes
1
answer
1k
views
Outer Query Column cannot be used in Clickhouse SELECT
I'm trying to select rows with the max value based on a metric. So, each row should be "compared" to its own max value based on the metric of that row. This can be done with the following ...
1
vote
1
answer
104
views
How to Update a column according to count of the element in another column
I have an SQLite table set up like this
log_table
id Street Status
---------- ---------- ----------
1 "main_street" 0
2 "...
1
vote
0
answers
40
views
Query to find id missing from an item that otherwise uses at least one id from the same group
I am trying to come up with a query that shows me which "feeds" make only partial use of a "rule group" by returning a list of rules that are "missing" from a given feed ...
1
vote
1
answer
60
views
Why does this select query provide the desired result but when modifed to an update it does not?
I'm trying to update a table to correct an error in the data that was loaded into SQLite. This is an example of the issue.
A code was skipped in arranging the data to be loaded, such that, beginning ...
1
vote
1
answer
148
views
Vectorized solution for getting a value from another row in the same dataframe
I have a dataframe that looks like this:
Category
Date
Value
PrevDate1
PrevDate2
A
2022-07-15
4
2022-07-01
2022-07-02
B
2022-07-16
2
2022-07-08
2022-07-09
B
2022-07-17
6
2022-07-05
2022-07-16
A
...
2
votes
1
answer
60
views
Query fails with ORA-00904 on Oracle 11 but not on Oracle 19
Let p be a table of master items and for each master item we are to aggregate collection of detail items. Detail items are of two kinds from two different sources. This query fails with ORA-00904: &...
-1
votes
1
answer
453
views
Why does my GROUP BY statement in my subquery get ignored and give me duplicates? [duplicate]
I am using Proc SQL within SAS.
When I use the GROUP BY statement in my main query, I get this error:
NOTE: A GROUP BY clause has been discarded because neither the SELECT clause nor the optional ...
1
vote
2
answers
60
views
The Rows Holding the Group-wise Minimun of a Certain Column, but using an additional condition
From this dataset:
mysql> SELECT * FROM document_signature;
+----+-------------+-------------+---------+-------+-----------+
| id | document_id | employee_id | user_id | order | status |
+----+--...
0
votes
0
answers
26
views
Have a problem joining two queries in MySQL
Am trying to join two queries in mysql in phpmyadmin. it is giving me the following error: #1142 - SELECT command denied to user 'cpses_dikfgmbqhy'@'localhost' for table 'lGroup'
Bellow is the ...
0
votes
1
answer
47
views
Fetching recordset from array
I'm having a column in postgresql (Table-Information) containing json format data inside an array. The column also contains NULL data
Like:
Location
NULL
[{"city":"Mumbai","...
0
votes
1
answer
225
views
I want to convert exist clause into In clause of the following query
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products
WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);
I want to convert the existing ...
0
votes
1
answer
359
views
Optimize Query - select statement in case when
I am trying to compare two sets of transactions. One is from a store log and the other is from the accounting records. I have a with statement that creates a table comparing both transactions and ...
2
votes
2
answers
162
views
Nested MariaDB Query Slow
I am having performance issues with a query, I have 21 million records across the table, and 2 of the tables I'm looking in here have 8 million each; individually, they are very quick. But I've done a ...
1
vote
2
answers
6k
views
Error "more than one row returned by a subquery used as an expression"
I have the following 3 tables:
airport
airport_id name
1 Frankfurt
2 Paris
3 Amsterdam
area
areaid name airport_id
1 name1 2
2 name2 2
3 ...
0
votes
3
answers
37
views
SUbquery correlated
I'm trying to do a subquery correlated, but not getting the right answer. I'm tried query 'suv' vehicles and inside this suv vehicles I would like vehicles made by BMW, but I'm getting all vehicles ...
1
vote
1
answer
2k
views
Spark SQL Correlated column is not allowed in predicate
I have to join 2 tables in Spark such that the value of a column in first table is within the range of the columns in second table. There is no joining column between the two table hence I can not use ...
0
votes
1
answer
52
views
append subquery based on case- postgresql
My table is crash
id
jurisdiction
drugs_inv
alcohol_inv
dr_sex
severity_id
1
NT
true
false
Male
3
2
NSW
false
false
Male
3
3
WA
true
true
Female
3
4
WA
true
true
Male
4
I want to have a subquery ...
0
votes
2
answers
45
views
Is it possible to optimize this Oracle SQL query any further (EXISTS)?
Hi hoping to have help to optimize the query below, it is taking 4+ hours to run when comparing two larger tables with 55k and 1.6M rows respectively.
I have 2 tables Oppty and Acc and a query to ...
2
votes
1
answer
121
views
Correlated queries - In derived tables, can I have many nesting levels?
The main question and the question itself is: In derived tables, can I have many nesting levels?
Context:
I know that in MySQL you can't have correlated subqueries with two levels deep, but, using ...