Questions tagged [inner-query]
79 questions
1
vote
1 answer
SQL Outer Query NOT IN Inner Query referencing Outer Query
I have a bit of a T-SQL conundrum that appears to be working but I was wondering if someone could attempt to give me a breakdown as to what is happening here.Consider the following script:
SELECT *
FROM TableA a
WHERE a.CustomerID NOT IN (SELECT…

Xenophage
- 85
- 9
1
vote
4 answers
SQL - Do you have to repeat ORDER BY in outer query?
I have a query:
select t1.*
from t1
order by t1.date
This query in enclosed in another query:
select * from (select t1.*
from t1
order by t1.date) t2
Do you have to repeat the ORDER BY in the outer query?…

Pat Ilo
- 15
- 3
1
vote
1 answer
Inner query to match 'LIKE' results from another table
I have a table with data as below:
FILTER Table
**id filter**
4638 Aabe
4639 Aaby
4640 Aadl
4641 Aaga
4642 Aake
SURNAMES Table
**surnames**
Aaberge
Aabehut
Aabyuti
Aabytis
Aadlit …

Stackoverflow User
- 161
- 1
- 4
- 10
1
vote
1 answer
is same execution plan means same performance?
I have two queries for the same task
ONE:
select * from table1 t1
INNER JOIN table2 t2
ON t1.id=t2.id
TWO
select * from table1 t1
INNER JOIN (select * from table2) t2
ON t1.id=t2.id
I checked the execution plan for both the queries.Both…

gkarya42
- 429
- 6
- 22
1
vote
1 answer
Inner query(sub query) using LINQ to Entities that returns IEnumerable Lists within Lists
I am trying to get lists of Articles from table Article with list of categories that each article is listed onto. Say Article "A" has 3 Categories "1","2","3" and I have more than one articles with more than one categories. I want to get list of…

Alok Babu
- 101
- 1
- 6
1
vote
2 answers
Error in inner query , where as inner query independently when run dont generate error
Following is my query, this query is giving me following error Unknown column 'package_id' in 'where clause
insert into company_packages(
package_product_id
,product_id
,company_id
,user_id
,expiry_date
,discount)
values(
…

noobie-php
- 6,817
- 15
- 54
- 101
1
vote
2 answers
Equivalent to doing a join after the group by
I am looking to merge the following two queries into one:
select top 100 date, count(*) from sections
where content not like '%some condition%'
group by date
order by date;
select top 100 date, count(*) from sections
group by date
order by…

soandos
- 4,978
- 13
- 62
- 96
1
vote
1 answer
Inner queries on the same table - is there a better way?
I have these two tables (simplified versions)
Orders
owner_id | user_1 | user_2 | amount | order_id
-----------------------------------------------
1 | 2 | 3 | 100 | AAA
1 | 7 | 2 | 200 | BBB
2 | …

BeNdErR
- 17,471
- 21
- 72
- 103
1
vote
1 answer
How to find Last record in group
Below is my data table:
+----------+--------------+--------+-------+---------------+-------------+--------+
| RegionID | ReceivedDate | FdNo | FmNo | FromRegionID | ToRegionID | HFlag …

Adriano Santros
- 138
- 3
- 14
1
vote
1 answer
limit the result of a query based on group by
I'm doing a query on oracle to update a token in a table to do some work on the marked rows.
My problem is that I want to limit the number of rows updated each time to a specific batch size and also to a group by result.
It is kinda hard for me to…

Silva
- 270
- 4
- 16
1
vote
2 answers
Referring to a column from a different table in inner join select
I'm trying to join onto an inner query, which is having it's results filtered by a value in the other table, so I can select the top result and use a value in it multiple times in my main select statement, but I get the error as below:
The…

George Duckett
- 31,770
- 9
- 95
- 162
1
vote
2 answers
How to solve unknown alias column issue without using nested queries?
I've the query
SELECT ID,
post_title,
post_author,
max(case when meta_key='geo_latitude' then meta_value end) latitude,
max(case when meta_key='geo_longitude' then meta_value end) longitude,
( 3959 * acos( cos( radians(18.204540500000) )…

Mithun Sreedharan
- 49,883
- 70
- 181
- 236
0
votes
1 answer
SQL ERROR: The connection was not closed. The connection's current state is open
EDIT
After staring at this for 2 days, I do see one issue. I was still opening the original connection. So I changed the inner open statements to conn2.Open. Then, I changed the second inner query to where all the variables were number 3 instead…

James
- 3,765
- 4
- 48
- 79
0
votes
2 answers
How to run a query with an inner query in it in Django?
I'm trying to run a query with an inner query in it as shown below:
# Inner query
Product.objects.filter(category__in=Category.objects.get(pk=1))
But, I got the error below:
TypeError: 'Category' object is not…

Super Kai - Kazuya Ito
- 22,221
- 10
- 124
- 129
0
votes
1 answer
SQL queries, can't figure out how this query can work
How can you select max(table column), and on the from clause declare another table column? It doesn't make any sense - can anyone explain?
SELECT
Ord.SalesOrderID, Ord.OrderDate,
(SELECT MAX(OrdDet.UnitPrice)
FROM…

Henri Sula
- 41
- 6