Questions tagged [mysql-dependent-subquery]

Use this tag for questions related to a dependent (correlated) subquery in MySQL.

A correlated subquery is a subquery that contains a reference to a table that also appears in the outer query.

as stated in MySQL: 13.2.10.7 Correlated Subqueries.

Question tagged with talk about optimization and performance issues with this kind of queries, in addition to getting them right, etc. .

31 questions
0
votes
1 answer

How to get the operation type in devart MysqlDependency

I know I can get the table name that recently changed using Devart MysqlDependency by using the following code. void dependency_OnChange(object sender, Devart.Data.MySql.MySqlTableChangeEventArgs e) { string tableName=e.TableName; } But I want…
Hamreen Ahmad
  • 522
  • 5
  • 21
0
votes
1 answer

Sub query MySql with MIN()

With QT5.15.1, Windows 10 64, last Mysql connect: My query : SELECT ata, description, min(duedate) as duedate, tbocalendar, tbocalendar2, table_name FROM (SELECT ata, description, duedate1 AS duedate, tbocalendar, tbocalendar2, 'part_log' as…
0
votes
0 answers

How must a query look like for this complex data?

i'm stuck creating a complex query... maybe there is some help out there?? :) I've a table with device status. An entry is genereated for each device status change. What i want to have is an output where i can see the lastest per date of all devices…
0
votes
2 answers

optimizing SQL counts

I have to select a list of Catalogs from one table, and perform counts in two other tables: Stores and Categories. The counters should show how many Stores and Categories are linked to each Catalog. I have managed to get the functionality I need…
0
votes
1 answer

From the following tables, write a query to get the histogram of specialties of the unique physicians who have done the procedures

From the following tables, write a query to get the histogram of specialties of the unique physicians who have done the procedures but never did prescribe anything. Patient treatment table Patient Id | Event Name | Physician ID 1 Radiation 1000 2…
0
votes
1 answer

increment counter column in one table if ip address exists in another table MYSQL

I have a viewCount column in table_1. Every time a user with a new ip address visits the page I increment viewCount column in by 1. This is to keep record of how many people have visited the page. In table table_2, I keep the ip address of the users…
0
votes
0 answers

Mysql sub query id match to outer query

I have below query and I want to sub query id matched to the outer query and select the value for the same row as the parent query returns. Here It return more results in sub query and I use limit 1 but with this I get wrong results. select …
Hamayun Khan
  • 35
  • 1
  • 9
0
votes
3 answers

Subquery slowing down update

This query references ~3M records and now takes an absolute age to run. The data is taken from an Excel Spreadsheet with Cust/Invoices down rows and monthly values 2016 to current in columns. This query checks to see if there is a value in the…
aSystemOverload
  • 2,994
  • 18
  • 49
  • 73
0
votes
2 answers

getting subquery error in SQL

Trying to insert into some table using my current table . Here is the structure of my current Temptable: CustomerID Name Values FakeName 1 John 10apples 10apples_20oranges_30bananas 1 John 20oranges …
0
votes
1 answer

How to code a "multi-command" mysql query in php

Please note that this question is not about the mysql query per se, but HOW TO RUN IT from php. For lack of a better term, I called it a multi-command query. I have a query which runs perfectly in mysql commandline client, and in phpmyadmin, as…
PHPGuyZim
  • 15
  • 4
0
votes
1 answer

Why is this MySQL query poor performance (DEPENDENT_SUBQUERY)

explain select id, nome from bea_clientes where id in ( select group_concat(distinct(bea_clientes_id)) as list from bea_agenda where bea_clientes_id>0 and bea_agente_id…
Miguel
  • 3,349
  • 2
  • 32
  • 28
0
votes
1 answer

want the result as table should retrn all card type for one activity even though he has not done any particular cartype for that activity

i have table as employee_details.in employee_details have column as emp_code,activity_id,card_id,quantity. the table look like:- #emp_code activity_id card_id quantity 001 1 31 600 002 …
shyarry g
  • 345
  • 1
  • 3
  • 8
0
votes
1 answer

MySQL - can I avoid these correlated / dependant subqueries?

I have a MySQL query that I have been optimising, and currently it has 2 dependent / correlated subqueries. I was wondering if it was possible to re write to avoid these? SELECT * FROM `pp_slides` JOIN `pp_slide_content` ON `pp_slides`.`id`…
Matt Bryson
  • 2,286
  • 2
  • 22
  • 42
0
votes
3 answers

MySQL: very slow query using nested sub-query

QUERY: SELECT ( SELECT COUNT(cleanpoi.ID) FROM cleanpoi WHERE cleanpoi.EstablishmentID=parent.ID ) AS POIs, ( SELECT COUNT(ID) FROM cleanamenitymappings WHERE CleanPOIID IN ( SELECT…
hodl
  • 1,420
  • 12
  • 21
-1
votes
1 answer

MYSQL error code: 1054 Unknown column in where clause. Error occurring in Nested SubQueries

I am trying to get through a problem where there are multiple accounts of same scheme on same customer id. On a given txn date I want to retrieve the total Sanctioned Limit and total utilized amount from these accounts. Below is the SQL query I have…