Skip to main content

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.

1 vote
1 answer
66 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-...
Abhishek Kumar's user avatar
-1 votes
3 answers
195 views

SQL Syntax Select Custom String from an Array not selecting Correctly

The Issue: I am trying to select from multiple tables, Table A and B but this is mainly regarding the Only column I am choosing from Table B. The values in this column contain an Array of string. Aim ...
Glen Owen's user avatar
0 votes
0 answers
57 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 ...
AeroMaxx's user avatar
  • 207
0 votes
1 answer
31 views

SQL where clause with optional IDs

Create Proc prcEmployeeSearch( @empIds varchar(200)='' ) As Select empId, empName from tblEmployee Where empId in (select item from dbo.Split(@empIds,',') Go Exec prcEmployeeSearch '' Go Exec ...
Thamar 's user avatar
-1 votes
1 answer
79 views

How do I avoid sub-query duplication in my SQL query?

I'm working with MariaDB, and I'm trying to get data about my sales. Aside from general data, I want to get further data about both widgets and doohickeys. The issue is, my customers aren't ordinary ...
JXG's user avatar
  • 7,373
-1 votes
1 answer
505 views

MariaDB SQL Recursive query as subquery

I have a data structure where: a vendor has a contingent (multiple vendors can use the same contingent, that's why it is different tables) A contingent can also have a parent contingent (unlimited in ...
Dennis van de Hoef - Xiotin's user avatar
0 votes
1 answer
112 views

Subquery-error message-Different data types

I run the following SQL code from a public dataset: SELECT station_id,name FROM bigquery-public-data.new_york_citibike.citibike_stations WHERE station_id IN (Select start_station_id from bigquery-...
Panos's user avatar
  • 3
0 votes
1 answer
60 views

Microsoft SQL Server Error: "An expression of non-boolean type specified in a context where a condition is expected, near ','."

I'm trying to execute this query to find the employees with highest salary based on department. Inner query works but I'm getting error from my outer query. I'd highly appreciate it if someone can ...
mykeerat's user avatar
1 vote
0 answers
46 views

Ecto: subquery must return a single field

How do I translate this into ecto? SELECT * FROM mytable WHERE (url,"when") IN ( SELECT url, MAX("when") FROM mytable GROUP BY url ) it works fine in postgresql shell, but I ...
Drathier's user avatar
  • 14.4k
0 votes
2 answers
32 views

Using NOT IN( ... ) when subquery result a single NULL row

I get unexpected results for a NOT IN criteria, when the subquery returns a single NULL result row. There's two tables, brands and media. The goal is to get a result only including the brands that ...
Erik's user avatar
  • 85
0 votes
0 answers
180 views

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 ...
Arturo's user avatar
  • 1
0 votes
1 answer
38 views

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 ...
Sri's user avatar
  • 11
0 votes
1 answer
42 views

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 ...
Amit Erandole's user avatar
-1 votes
1 answer
35 views

MySQL: Finding the most efficient use of INNER JOIN with subquery

I have a working query using INNER JOIN and a subquery but was wondering if there is a more effient way of writing it. with prl as ( SELECT `number`, creator, notes FROM ratings INNER JOIN ...
mcos's user avatar
  • 33
0 votes
0 answers
79 views

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, ...
BCT's user avatar
  • 11

15 30 50 per page
1
2 3 4 5
9