11,464 questions
2
votes
1
answer
83
views
PostgreSQL correlated query ignore WHERE clause [duplicate]
For each customer_id, I want to find the first delivery order. For each row of Delivery, I compare order_date with the smallest order_date of that customer_id.
Why does the SELECT statement below only ...
0
votes
1
answer
52
views
MS Access 2016 Subquery
I have gone all around the houses with this trying to use a subqueries etc but just cannot get this to work and I am thinking it should be easy. So this is what i have:
SELECT DISTINCT Register....
1
vote
1
answer
75
views
MariaDb Use Column In primary Query in sub Query
I have a table that has store names, product codes and prices.
I need to pull the minimum price of a product and display a list of the product codes with their minimum price, where it all falls down ...
-5
votes
1
answer
97
views
Filter table using result from another Select [closed]
I want to query table2 to get results having field field_b which corresponds to the first query result's list. (More as a LIKE; the comparison won't match perfectly).
I have a table with many fields, ...
1
vote
3
answers
136
views
Case of null value based on key column when returning rows without a certain match in another table
The employee table lists the employees and the history table records hire and term dates as separate rows.
I need to write a query that identifies all employees from the employee table that are ...
-1
votes
1
answer
58
views
Linking union query to subquery
I'm trying to write a query that will join a subquery with a large union query and I'm having some trouble.
Below is the subquery:
SELECT DISTINCT X.JOB, FOO.PART FROM
(SELECT C.PART, C.ORDER_NO, C....
-2
votes
1
answer
69
views
Wordpress Subquery returns more than 1 row for query plugin delete users by role and date [closed]
I work on this plugin for Wordpress to delete users with a subscriber role and 30 days since joining us; users are active or not.
I cannot correct this error after activating.
if ( !defined('ABSPATH') ...
-3
votes
1
answer
59
views
error 1046 in subquery inserting data from specific columns to another table [closed]
I am trying to copy a few fields of video information from one MariaDB table to another using a subquery, decoupling some video info from a classified ads table for later refactoring.
video:
id (int ...
0
votes
1
answer
73
views
Delete (or Select) data with subquery using T-SQL
I am trying to come up with T-SQL query to delete data based on these conditions:
Find data that have same Email.
If that user has both AllLocations 'Yes' or 'No', delete entry/entries that are not ...
-2
votes
1
answer
67
views
Why is my SQL subquery returning an error in PostgreSQL when comparing salaries? [closed]
I'm trying to retrieve employees who earn more than the department's average salary using a subquery in PostgreSQL.
SELECT
employee_id,
first_name,
salary
FROM
employees e
WHERE
e....
1
vote
0
answers
104
views
Snowflake: "Unsupported subquery type cannot be evaluated" when using a function with a subquery on a JSON column
In Snowflake I'm trying to de-identify data stored in a JSON column based on configurations in a separate table. I created a custom SQL function DEIDENTIFY_JSON which uses a subquery to look up the de-...
-1
votes
2
answers
87
views
How to delete a row knowing its row index in a nested SQL statement where the table doesn't have a row index column?
My app has a function that deletes a specific row in a SQLite table based on the row index or position, but the table doesn't have a column that stores a row index for easy access. My app retrieves ...
-1
votes
1
answer
57
views
I'm trying to replace not exist in with left join, but my query is not returning the same result
so I'm trying to using left join instead using not exist (which I always disliked), but somehow I'm not getting the same result.
Original query that returns the correct result:
select o.number, o....
-2
votes
4
answers
145
views
Select where x is true but not y [closed]
I have a table that stores customer transaction data. I want to select all customers that have purchased item 1 (64244), but remove/ignore them from the results once they've purchased item 2 (64270). ...
0
votes
1
answer
74
views
SQL query returns a 2nd result from a subquery
I have two tables
Table 1
ID
Parent ID
00001256
00001298
00001256
00087612
00098542
00009214
00087612
00087343
00098542
00456336
Table 2
ID
Flag
00001256
TRUE
10000000
00087612
TRUE
10000001
10000002
...
-2
votes
2
answers
113
views
Using Select TOP 1 in a subquery [closed]
I have the following query that is not returning the result that I need, which is the top contact from each organisation, but what I am getting is the top contact repeated for each row, not for each ...
0
votes
2
answers
140
views
Difference in query and error even though distinct values
It is Bigquery and below are the sample tables and contents
dde-demo-d001.sap_crm.transactions_bkup
case_guid
transaction_header_guid
005056935CD81EEF92DF522476D53CAB
00505693-5CD8-1EEF-92DF-...
-3
votes
1
answer
57
views
Using multiple columns from a nested SELECT in an INSERT query in sqlite3 [duplicate]
I have to write an INSERT query in sqlite3 that uses the values of multiple columns from the same nested query.
In the example below i need to insert into table_a multiple values from the same nested ...
0
votes
1
answer
62
views
Subquery in where clause with CriteriaQuery for greater and equal operator
I have following SQL query, for which I want to write a CriteriaQuery
select * from EntityA ea where ea.lastUpdateTS >= (select creationDate from EntityB where status='PUBLISHED' order by ...
0
votes
1
answer
100
views
SQL using a hierarchy to pick the correct price
I have to find a price by choosing the correct price out 3 options in a hierarchy
from highest to lowest
if "tran_type" is Quot than choose this price over all from the [price] column and ...
0
votes
0
answers
32
views
MS Access: Issue with Lookup Field in Nested Queries
I’m encountering an issue in MS Access with a subquery that works perfectly as a standalone query. Here’s the standalone query:
SELECT
[**Site_Conf_Details].*,
IIf([Sharing] = -1, "Yes", ...
-2
votes
2
answers
261
views
Using SQL , how do I select the max values when there is more than one with the same max value?
I am trying to select the maximum ImportDate for each person. For this person "Bob James" he should have the last 2 rows selected with ID 267311 and 267342. I need to see every column in the ...
0
votes
1
answer
65
views
Am I able to use this subquery to solve this SQL problem without having to use GROUP BY?
Am I able to use this subquery to solve this SQL problem without having to use GROUP BY?
For each continent show the continent and number of countries with populations of at least 10 million.
world(...
0
votes
2
answers
93
views
How to return the COUNT of two different parameters?
I'm trying to return how many 'males' or 'females' are counted in each specific event for the products brand name column.
I tried to use subqueries and use the same syntax for both genders. Since I ...
0
votes
1
answer
96
views
Separate query for items missing on first query
Looking to be able to pull a code with a separate query if it's missing from that customers list but still in the WHERE IN clause. So for this the query I have only works on items that are present in ...
1
vote
1
answer
70
views
Aliasing conditions in Postgresql
So I am new to Postgresl and am trying to get familiar with nested queries and how they work as there seems to be some conditions that add to what intuition seems to tell me.
I learned, at least I ...
0
votes
2
answers
52
views
MS Access Joining Tables After totaling
I have tables A, B, C, and D.
They all have the following fields:
Division, Vendor, Deal, Reference, and Amount.
I want my final table to contain Division, Vendor, Deal, Reference, and 4 separate ...
0
votes
3
answers
115
views
select users with same SSN and MAX process date DB2
I need to find all the users who have a MAX Process date. There are often multiple records for the same person but different process dates.
PROCESS_DATE | SSN | Amount | CODE | SOURCE | ...
1
vote
1
answer
105
views
PostgreSQL Case with a subquery using a different where clause
I am trying to query the correct price by going through and choosing between 2 prices.
These are in order of importance from highest to lowest:
if [tran_type] is equal to Quot than choose this price
...
-1
votes
1
answer
98
views
Does SQLite support ALL and ANY keywords?
Does SQLite support ALL and ANY keywords?
I keep facing syntax error while using them.
SELECT name, price
FROM products
WHERE price > ALL (
SELECT price FROM products WHERE category = '...
0
votes
2
answers
60
views
Oracle SQL - Using subquery in Group By
I have two queries that run fine on their own and I need to combine them. One query uses "Group By" and the other query uses a subquery.
First Query:
SELECT
LH.AISLE AS "Aisle",...
0
votes
1
answer
28
views
Produce 3 columns: one patient subject, date of 1st event, date of 2nd event
Working with a patient visits during a trial. THey're scheduled to come in at specific instances, visit ID- Safety Visit Cycle 01 Day01... cycle 2 day 01.. and so on. I also have a study group ...
-3
votes
2
answers
70
views
Subquery to match most recent child table record
Scenario
Requirement.
select all rules that are inactive (Rule_table.Status) matching the most recent audit record with audit_text='status_change' where its created date has passed 6 months.
In the ...
0
votes
1
answer
75
views
How to use my substring column to join a subquery to the parent query
I have a table which contains a data field of assorted IDs written in plain text.
Other_ID
Data
Date
123
user_id:098; metdata:[ID: 6482]
2024-10-13
456
user_id:754; metdata:[ID: 0743]
2024-10-12
123
...
1
vote
1
answer
117
views
Conditionally update multiple columns with same CASE subquery
Currently using PostgreSQL 16.4. I looked at this post but it didn't cover my use case.
I would like to conditionally update two (or more) columns with the same condition, so I don't have to rewrite ...
-1
votes
1
answer
45
views
Linking data based off a value within a group [closed]
Good afternoon, I have two tables (call them table a and b), the first has one row per id, with a number attributed too it as follows:
| ID | Number |
| 1 | 10 |
| 2 | 21 |
| 3 | ...
0
votes
1
answer
51
views
MySQL query to UPDATE column with value in different column of different record possibly using subquery
I am very rusty on MySQL and having trouble updating columns based on a different column in a different record. I'm thinking I need to do a sub-query.
The table being queried is an aggregate of other ...
0
votes
2
answers
157
views
How do I access a field from the main query inside a sub query in mySQL?
I have 3 tables: products, product_options and product_option_choices. Products can have multiple options, options can have multiple choices.
Choices can adjust the main product price (...
0
votes
1
answer
77
views
Aggregation: Category missing in SQL subquery
my base data:
Process ID
Location
Date
Timeliness
2030608
New York
May 24
in time
2067393
Ohio
May 24
overdue
1329306
Ohio
May 24
in time
1740814
Ohio
June 24
overdue
1924676
Chicago
May 24
overdue
...
1
vote
1
answer
73
views
MySQL performance difference between join and subquery
Here are two sql :
the first uses join method to execute
the second one uses dependent subquery to execute
IN the slow log ,we can see the examined rows and query time. When the tow methos have the ...
-1
votes
1
answer
68
views
id column in the subquery where clause exists in both tables, the id it is using is from the wrong table
Table tblStudents columns: id, name, gender, SchoolName, SchoolId.
Table tblSchool columns: id, name, location.
select name,
(select name
from tblStudents as a
where a.SchoolId=id
...
-4
votes
2
answers
119
views
How to make this subquery return more than one row?
I select data from temporary table:
CREATE TEMPORARY TABLE IF NOT EXISTS "tmp"
(
"fuel_type" TEXT,
"litres" NUMERIC(8,2),
"is_rent" BOOLEAN
);
...
-4
votes
1
answer
81
views
SQL : How to subquery using outer alias with case expression [closed]
How can I create a subquery that uses the value of an outer column for a subquery which uses a case expression?
SQL Example:
SELECT
name,
average,
crnt,
goodFactor
FROM
(
"Crispy ...
0
votes
3
answers
125
views
How to correct this SQL statement?
Service table:
Car_id
Service Date
101
2016-02-05
102
2017-02-06
103
2017-05-07
104
2017-02-08
105
2017-05-09
106
2016-03-10
101
2016-08-10
101
2016-02-20
106
2016-08-15
106
2016-12-20
Expected result:...
0
votes
1
answer
129
views
Error 'Table must be specified for selection' in SQL Query in SAP Business One
I am working on a SQL query in SAP Business One, and I keep encountering the following error:
Table must be specified for selection.
The query I am using is as follows:
SELECT
o."DocNum&...
0
votes
0
answers
44
views
Subquery in mongodb using not in
I have some problems getting a query with the following:
I want to select the records whose date is less than or equal to a date given by parameters but I also have to take into account that the ...
-1
votes
2
answers
94
views
Execute second SQL query if the first one returns less rows than the limit
I have two SQL queries like this for postgresql:
The first query is fetching subscriptions that were never synced or that were updated recently and synced a long time ago:
SELECT *
FROM subscriptions
...
-1
votes
1
answer
42
views
Optimize query with min
I have table a where I have
Transaction_id (not unique, for one transaction it could be many string value for other status), status (for example A001,A002,A003), string value. I want to join to my ...
0
votes
0
answers
31
views
How to get records for one customer that exist in two tables but in one of them there are more [duplicate]
How to get records for one customer that exist in two tables but in one of them there are more records. For example in the fist table there are 3 records with different amounts and in the second there ...
1
vote
1
answer
2k
views
Cannot adapt type 'dict' using placeholder '%s' (format: AUTO) in SQLAlchemy ORM
I want check whether the particular email template is used in any other model instance and model Rule we have action(JSONB) while running query below query i'm getting error
I had added the sample ...