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
1 answer

Getting "Unsupported subquery type cannot be evaluated" when using UPPER in Snowflake IN Subquery

I have a Snowflake table as following: create table field_names_to_retrieve("QualifiedApiName" varchar(80)); INSERT INTO field_names_to_retrieve VALUES ('reason'); INSERT INTO field_names_to_retrieve VALUES ('reason__c'); INSERT INTO…
0
votes
1 answer

Passing different column values to where clause

SELECT pims.icicimedicalexaminerreport.id, pims.icicimerfemaleapplicant.adversemenstrualid, pims.icicimerfemaleapplicant.pregnantid, pims.icicimerfemaleapplicant.miscarriageabortionid, …
nevas
  • 81
  • 1
  • 7
0
votes
1 answer

Using IN clause with subqueries. The compared column names are different

I have a table of elements and a table specifying the hierarchy between those elements. Knowing the alias of one element I want to get the aliases of its child elements. The columns specifying the "Element ID" parameter have different name in the…
0
votes
0 answers

MySql, alternatives to repeating Select IN (Select()) when UNION

I've been tackling this for a long time and I've decided I will ask to see if someone can suggest something before my head explodes. Here is the query I'm running, it's just repeating the same sub-sub-query multiple times within the sub-queries. I…
Sidupac
  • 651
  • 7
  • 11
0
votes
2 answers

MySQL: select row only where closest to date has column value

I want to return all rows that were public in May (2019-05), so if a row was turned to draft (and not back to public) at any point before the end of May, I don't want it. For example: id | post_id | status | date ------------------------- 1 | 1 …
HWD
  • 1,547
  • 7
  • 36
  • 72
0
votes
1 answer

Subquery using the "IN" Keyword

The problem: In a car database there is a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice. Use a subquery along with IN to list all the Model Names with a Sticker…
user8964654
  • 87
  • 1
  • 9
0
votes
1 answer

SQL making subquery work for each independent ID instead of taking the values from several IDs

This is for finding top 10 advertiser apps'(based on # of installs) avg. eCPM (calculation below in query). It works accurately if I run it with one publisher ID only. Issue: when using more than one publishing app ID, the subquery (C2) reads it as…
0
votes
2 answers

how to combine the rows of a multi row sub query with a conditional statement to be used in In in T-sql

I'm trying to get the records of the Parent Department if exists from the view PayrollViewas well the child departments provided DepartmentSecurityMode=2. The rows are filtered on parent Department Id. This is what I tried but it shows me the…
Raida Adn
  • 405
  • 1
  • 6
  • 17
0
votes
0 answers

Join View vs. temp table with aggregate function and case when

I have a large query with multiple joins including a a subquery (saved as a view). Essentially it looks like this. Select sum(a.amount), case when a.criteria1 = 'c' then 'something' when v.min_rank = 2 then 'something else' .... else…
0
votes
1 answer

MySql subquery runs instead of returning error

I faced some weird mysql subquery issues ... UPDATE site_plugin_products_items SET item_distributor = 176 WHERE item_id in ( SELECT item_id FROM `site_plugin_products_field_values` WHERE value_val in ( 554, 1384 , 785 ) ) I the…
Emanuel
  • 359
  • 4
  • 21
0
votes
1 answer

SQL Server - Select results by a group expression but filter them based on another group expression

I am dealing with a problem where I need to aggregate data based on a criteria. The situation is a follow: I have consumption data from an application on database and I need to show it to be displayed in a table. People can aggregate data based on…
R. Godinho
  • 15
  • 5
0
votes
0 answers

Mysql alias and where condition

SELECT ENTERED_COUNT, MINUTES, USER, DATE_ENTERED , (SELECT SUM(ENTERED_COUNT * MINUTES) FROM tbl_coding WHERE USER = 111 AND DATE_ENTERED >= '2018-03-01' AND DATE_ENTERED <='2019-03-09' GROUP BY DATE_ENTERED ) AS ECNT , (SELECT SUM(ENTERED_COUNT…
0
votes
1 answer

2 sub queries in insert statement values in MS SQL Server Compact Edition 4.0

Specifically I'm using SQL Server Compact 4.0, if that makes a difference. I have 3 tables (note,userTable,verse). the user and verse table have no correlation except in this note table, so I can't do a single subquery joining the two tables. INSERT…
0
votes
2 answers

How to pass comma separated value in mysql query?

I am using a sub query to get all qcodes and passing it as a parameter to another query in mysql. But inner query is returning value like - SELECT qcodes FROM boardmst WHERE id=10 10002','10028','10031','10202','10226 so how to parse it to pass in…
Yugal Kishor Bais
  • 199
  • 1
  • 1
  • 8
0
votes
1 answer

Better approach for multiple negated subqueries

I have a few tables defined like this: CREATE TABLE `member` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, ... ) CREATE TABLE `members_to_delete` ( `id` bigint(20), ... ) CREATE TABLE `message` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, …
Bruce P
  • 19,995
  • 8
  • 63
  • 73
1 2 3
8 9