Questions tagged [inner-query]

79 questions
11
votes
3 answers

Q (kdb): nested where query

What are the ways to in Q to use the results of a nested query in a where clause? I'm looking for something similar to SQL statement. select from food where type_id in ( select type_id from types where type_name = "fruit" )
Leonid
  • 22,360
  • 25
  • 67
  • 91
5
votes
3 answers

SQL INNER QUERY returns more than one value in an UPDATE query

I have a table to be updated using records of another table and I am doing this to bring over information from one system (database) to another. The scenario is bit complex, but I desperately need help :-s There are 3 tables - component , scan and…
mithilatw
  • 908
  • 1
  • 10
  • 29
4
votes
3 answers

Oracle SQL Reuse sub query inside VIEW

I am trying to set up a view which could potentially contain 1000's of records. Some of the fields requires subqueries which return the exact same data. I was wondering if I can query this once, within the view, instead of running it each time.…
xchagger
  • 133
  • 1
  • 9
4
votes
2 answers

MySQL Sum + Inner Query in same table

This is my MySQL table layout +----+---------+----------+---------+-------+ | id | AssetId | FromType | ToType | Amount | +----+---------+----------+---------+-------+ | 1 | 1 | Bank | Asset | 10000…
Eugine Joseph
  • 1,552
  • 3
  • 18
  • 40
3
votes
1 answer

SQL (ORACLE): inner-query with 2 or more related/paired container-query "pointers"

FOR ALL THOSE "OMG! HE IS USING IMAGES :O :O :O" PEOPLE (ORIGINAL POST UNDER THIS): I've a table: date1 | id1 | value date1 | id2 | value date1 | id3 | value date1 | id4 | value ------------------- date2 | id1 | value date2 | id2 | value date2 | id5…
Lightworker
  • 593
  • 1
  • 5
  • 18
3
votes
1 answer

Using the current row in the update statement

What I'm trying to do is the following: I have a table with multiple authors SingleAuthor. This table sometimes contains the same author more than once. What I want to do is update the table and add the author specific number. For…
Rick Hoving
  • 3,585
  • 3
  • 29
  • 49
2
votes
5 answers

How to pass inner query in mongodb from javascript

I want to create an aggregation pipeline which one of the matches use results from other collection (inner query). This is an example: db.users.aggregate([ {"$match":{"id":{"$in":["0","1","2"]},"p": {$in: db.groups.distinct("p",…
mspapant
  • 1,860
  • 1
  • 22
  • 31
2
votes
4 answers

SQL Performance: Filter first or Join first

I am having three tables viz., Employees, Department and Grievance. The Employees table has over a million records. I need to find the details of the employee, his/her department and grievances raised by him/her. I could think of the below two…
Pulkit
  • 43
  • 6
2
votes
1 answer

Apache Impala Inner Query restriction for FROM statement

This IMPALA sub query restriction consumed too much of my time. So I decided to post here to save people some time. If you are making an inner query for the FROM part you cant make your standard SQL to work. I.e: select count(*) from (SELECT *…
math_law
  • 391
  • 1
  • 4
  • 16
2
votes
0 answers

filter solr inner query with outer query values

Is there, in SOLR, a way to use values from outer query in inner query. Basically what i want to do, is to compare two documents I have made SQL equivalent query. But no idea how to implement in SOLR select * from Versions v1 where 1=1 and…
maxlego
  • 4,864
  • 3
  • 31
  • 38
2
votes
1 answer

Can we use column name in mysql in clause?

SELECT `e`.`id`, `e`.`title`, `e`.`description`, `e`.`event_time`,(SELECT GROUP_CONCAT( name SEPARATOR " | " ) FROM `ar_products` WHERE id IN **(e.products)** AS products FROM events e; I have list of comma separated product id's in events table…
maxatmin.com
  • 51
  • 1
  • 4
2
votes
1 answer

mysql filter by result of sub query

i have this Query : SELECT a.*, a.id AS id_player, (SELECT COUNT(id) FROM `vd7qw_footsal_goals` WHERE a.id = id_player AND g.id = id_group) AS goals, team.* FROM `vd7qw_footsal_players` AS a LEFT JOIN vd7qw_footsal_teams AS team ON team.id=…
Viszman
  • 1,378
  • 1
  • 17
  • 47
1
vote
3 answers

Mysql Query: Find Customer W/Orders but without Payment

As the title says, i am trying to find the customer's who have made orders but have not made payments yet. I have Three tables; Customers, Payments, Orders The sql i have so far gives me (nested query) all the customers without payments, the outer…
Warz
  • 7,386
  • 14
  • 68
  • 120
1
vote
1 answer

How to express "either the single resulting record or NULL", without an inner-query LIMIT?

Consider the following query: SELECT (SELECT MIN(col1) FROM table1) = 7; Assuming col1 is non-NULLable, this will yield either true or false - or possibly NULL when table1 is empty; But now suppose I have: SELECT ( SELECT FIRST_VALUE (col2)…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

Update table column with value from inner query?

I have the following table: create table public.dctable ( prod int, customer varchar(100), city varchar(100), num int, tim datetime, dc smallint ); insert into dctable values (1, 'Jim', 'Venice', 5, '2015-08-27…
Kenobi
  • 465
  • 6
  • 13
1
2 3 4 5 6