Questions tagged [nested-select]

Nested SELECT is used when some select query is used under a select query like SELECT * FROM (SELECT * FROM TABLE)

46 questions
6
votes
4 answers

How do I Compare columns of records from the same table?

Here is my testing table data: Testing ID Name Payment_Date Fee Amt 1 BankA 2016-04-01 100 20000 2 BankB 2016-04-02 200 10000 3 BankA …
Chhun Panharath
  • 136
  • 1
  • 10
5
votes
1 answer

MYSQL Select multiple columns depending on a specific column

I would like to do a SELECT request witch manage to get 2 columns of VALUE (DESKTOP & MOBILE) depending on the PLATFORM value. Here is an example table: +----+---------+------+----------+-------+ | ID | PROJECT | NAME | PLATFORM | VALUE…
Jack
  • 802
  • 6
  • 12
2
votes
2 answers

nested select - multi part identifier not bound error

I have written the following query, but I am getting a multi part identifier not bound error, as I am trying to filter the sub query, using values from the first inner join, from outside the sub select. SELECT runners.id, wins FROM…
Laura Baker
  • 497
  • 5
  • 14
2
votes
3 answers

SQL Query; how to display info only where the number of entries in one row is greater than the number of entries in another?

Super simplified code: SELECT lots_of_stuff. , A.more_stuff , B.stuff , C.things FROM table A, table B, table C, where (B.more_stuff = A.stuff) and things and stuff and lots more things and this query has so much crap believe me and…
1
vote
1 answer

sqlite, python, apsw: trouble parameterizing nested select

I am trying to query some data of an sqlite database with a nested select statement. The final result of the query needs to be restricted by a WHERE clause, so I put brackets around the "inner" select statement, named it s1, and put another select…
Judith
  • 11
  • 1
1
vote
1 answer

SQL to Sequelize with nested select

Need to write the following SQL Query in Sequelize Node js select a, b, c from ( select tbl.*, count(*) over(partition by a) cnt, row_number() over (partition by a order by b) brn, row_number() over (partition by a order by…
Nicole
  • 21
  • 5
1
vote
2 answers

Select city in Continent = 'Europe' with Max Population but without using Joins (MySQL)

I'm learning to write SQL queries in MySQL Workbench. At this moment I have two tables: city table country table Is it possible to SELECT name of city With MAX population from city table which are in Continent of 'Europe', but without using Joins?…
1
vote
1 answer

sql store nested select subquery resultset into variable

I am trying to get next/previous record from a result-set that is an output of inner select query. Here's my query: select qs.* from ( select tsk.id, tsk.request_id, tsk.category_group, tsk.category, …
Azima
  • 3,835
  • 15
  • 49
  • 95
1
vote
1 answer

sql sub queries aggregation

I have a fairly complicated multiple nested query set that I need to aggregate in to one view but I keep getting a metric does not exist error. Each component piece runs fine but when I bring them all together I get and error that states Invalid…
1
vote
1 answer

MySQL - Missing rows due to NULL nested SELECT and JOIN

I have four tables at the moment, users, user_groups, user_group_memberships and user_group_permissions. user_group_memberships is used to link a users.id to a user_groups.user_id and user_group_permissions is used to link members of a group to a…
Arbiter
  • 450
  • 5
  • 26
1
vote
2 answers

NULLS in select subqueries

I have two tables. One showing working pattern names and one showing the hours worked for each day with the pattern id in each column. I want it to link so that the hours for each day appear on one row. For each pattern there is a maximum of 28 so…
1
vote
3 answers

Inefficiency of join table a to table b on matching sub-string... thoughts?

Background: First, I have a schema with a table named patients with which I am concerned with patient_id and alerts (alerts is a string of characters, where each character represents some arbitrary value/meaning). Second, each 'patient' is part of a…
Phillip Weber
  • 554
  • 3
  • 9
1
vote
1 answer

How to use nested SELECT statements in sql?

I have two tables as Book +------+--------------+--------+----------+ | bkey | bname | nochap | b_id | +------+--------------+--------+----------+ | 1 | Let Us C | 17 | luc13 | | 2 | OOP with C++ | 17 | oopwcpp6…
Siraj Alam
  • 9,217
  • 9
  • 53
  • 65
1
vote
0 answers

Incorrect syntax near the keyword 'select'. What I did wrong?

with Tagvote as ( SELECT --TOP 20 p.OwnerUserId, t.TagName, COUNT(*) over (partition by p.OwnerUserId Order by t.TagName)AS UpVotes FROM Tags t INNER JOIN PostTags pt ON pt.TagId = t.Id INNER JOIN Posts p ON p.ParentId = pt.PostId INNER JOIN Votes…
Xiaomeng
  • 43
  • 8
1
vote
2 answers

AND not working with Nested Select sql query

I have an SQL query that selects a minimum value from a column and requires another value to be equal to 1. I am using a nested select and attempting to use an AND statement. However, after adding the AND, the query results with zero results.…
Pj Rigor
  • 391
  • 6
  • 17
1
2 3 4