Questions tagged [in-subquery]

Use this tag for questions related to subqueries (i.e. a query that is nested inside a SELECT, INSERT, etc.), that use IN at their outer statement.

An example of an is:

WHERE th.parent = 1015 IN (
    SELECT DISTINCT(th1.tid)
    ...
);

as demonstrated in MySQL DELETE FROM with subquery as condition.

Note that this tag is general in its scope, i.e. that it is not restricted in SQL questions only, but any question referring to this type of IN subqueries is welcome to use this tag.

128 questions
0
votes
0 answers

Right way for passing parameters for IN-subquery (classic ASP, ADODB.Command)

good afternoon i'm going crazy with passing parameters to a very simple query with a subquery; i wrote hundreds of complicated queries, i'm afraid my fault is just in passing parameters to the subquery or everything else seems very normally…
Arturo
  • 1
  • 1
0
votes
1 answer

Update query using Subquery in PLSql Server

I compared table1 data table2 data, and filtered data which was not existed in table1. I want to make both tables rows count equal. For that, I need to set is_active = 0 in table2, where the data was not existed in table1. Example:: UPDATE table2…
Sri
  • 11
  • 1
0
votes
1 answer

Get field from MYSQL subquery from outer main query

In my mysql db I have an employee table (EMP) and a department table (DEPT) and want to find employees with highest salary in each department. So first I grouped the departments like this SELECT dept.DNAME as department, MAX(emp.SAL) as…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
0
votes
0 answers

Converting JOIN to Subquery

I am trying to figure out how to convert a JOIN to a subquery. I am using AdventureWorks2019 database and I am pulling data from two tables. My JOIN statement I created is: SELECT FirstName, MiddleName, LastName, StateProvinceID FROM Person.Person…
BCT
  • 11
  • 1
0
votes
0 answers

Looking for something to replace INTERSECT in ISQL

I am trying to construct a query to handle multiple filters in ISQL. I have a query that provides the answers I need when I'm using MSSQL, but it uses the INTERSECT command, which appears not to be present in ISQL. I have the following…
TychaBrahe
  • 55
  • 6
0
votes
1 answer

While querying IQueryable with linq subquery it fail

I just want use an IQueryable fetched from EF Core to filter customers against a filter, in this case the filter is another list of customers. After hours of search I found this and it looks works ok, then I tried do this: List
joe
  • 3
  • 2
0
votes
1 answer

How do I force SQLAlchemy ORM to include table in subquery?

I have two tables user and visitors with the following contents: users: +----+-------------+ | id | email | +----+-------------+ | 1 | a.b@foo.com | | 2 | b.c@bar.com | +----+-------------+ visitors: +----+---------+------+ | id | user_id |…
Midnight
  • 373
  • 2
  • 11
0
votes
1 answer

Apply filter on subquery with multiple values

I Have a table USER_DETAILS and I have another table named PASSWORD USER_DETAILS contains:- id| name| phone_number PASSWORD contains:- id|user_id| password| created_at | password_hint password can contain multiple entries for a user Now I want to…
Newton8989
  • 300
  • 1
  • 4
  • 22
0
votes
1 answer

How do I select records from 21days (or more) ago? (sqlite)

I'm trying to select patients who have received ONE dose of Comirnaty, AND are due for their next dose (vac_date was 21 days ago or more). The following query got me everyone who has received ONE dose of Comirnaty: SELECT NHI_id, fname, lname,…
vtk91
  • 13
  • 5
0
votes
1 answer

Multiple columns in a subquery

I am trying to find the products selected in previous week vs products selected for this week to find the churn in selection decision. Currently I am doing it for a single site and the result works fine with the correct number of records. Now I want…
Sankalp
  • 21
  • 3
0
votes
0 answers

How to join an entity and a custom select using CriteriaBuilder

I need to convert a certain query to JPA using CriteriaBuilder. The query looks like this: SELECT * FROM ENTITY1 a INNER JOIN ( SELECT * FROM ENTITY2 b where b.STARTDATE = '2019-10-31T00:00:00.000+0100' ) ON ENTITY2.ID =…
0
votes
1 answer

Postgresql: One-To-Many Relationship With Multiple Conditions On The Many Side

I have a Students table that has the following columns id student_name And Courses table id student_id //a foreign key course_name credits It is a one to many relationship(one student might have multiple courses). I want to list all the students…
VFX
  • 496
  • 4
  • 13
0
votes
1 answer

Using nested query twice within one query - for FROM and WHERE

I am trying to figure out why the following Microsoft SQL code does not work. I simplified the query as it is quite complex. Basically the part that is not working is the second nested subquery (line FROM a) - I get an error: Invalid object name…
joanxm
  • 1
0
votes
1 answer

Subquery within LIKE condition

Suppose I have the following hierarchical table: +-------+----------+-------+-------------------------+-----------------+--------+ | ID | ParentID | Name | Path | InheritanceFlag | ToEdit…
RegularNormalDayGuy
  • 685
  • 1
  • 8
  • 25
0
votes
0 answers

Pymongo: Subqueries with $lookup for the same collection and $in for certain ids. Is this the right way?

I''m new to MongoDB and I need to do kind of a subquery, in which I want: Return the count of records for top3 cariers (the array in $in) for each week. My collection is as…
neverMind
  • 1,757
  • 4
  • 29
  • 41
1 2 3
8 9