Solved

mysql DELETE  "gets stuck"

Posted on 2014-12-01
6
221 Views
Last Modified: 2014-12-01
I've inherited the following "nested" DELETE query,
where the desire is to delete those records in the Purchase_order_details table that
are referred to in the Sales_order_details  table.

tblPOdetails                           tblSOdetails
po_detail_key    <-------------- po_detail_key
                                                 so_header_key   =   123456  (a specific value when handed to mySQL)

DELETE FROM tblPurchase_order_details       
                        WHERE po_detail_key IN
                              (SELECT po_detail_key FROM tblSales_order_details
                                    WHERE so_header_key='{$SOHID']}'
                              )

The server shows the mySQL state of this query to be          "Sending data"
and it's stuck there until i restart mySQL on the server.

I can unravel the "nested" query to be implemented using a PHP loop, but wondering if there's
a way it can work WITHIN mySQL?

p.s. it's INNODB with no constraints defined,  all other queries work fine.
the design, etc.  had been translated from an ASP/Microsoft implementation from 15+ yrs ago.
0
Comment
Question by:willsherwood
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40474656
This '{$SOHID']}' is not a valid anything that I know of.  Please post the actual code in the 'code' format so we can see what you are actually doing.  You can replace any sensitive data but otherwise keep the code as it is found.  Like this...

DELETE FROM tblPurchase_order_details       
                        WHERE po_detail_key IN
                              (SELECT po_detail_key FROM tblSales_order_details
                                    WHERE so_header_key='{$SOHID']}'
                              ) 

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40474660
Is this your exact sql as you have a square bracket and a nested apostrophe

'{$SOHID']}'

DELETE tblPurchase_order_details FROM  tblPurchase_order_details 
	INNER JOIN tblSales_order_details 
		ON tblSales_order_details.po_detail_key = tblPurchase_order_details.po_detail_key
	WHERE so_header_key='{$SOHID}'

Open in new window

0
 

Author Comment

by:willsherwood
ID: 40474713
sorry for the copy/paste typo.

the  '{$SOHID}'  is a PHP variable that expands to a literal/constant for the query

i'll try your INNER JOIN now !
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Closing Comment

by:willsherwood
ID: 40474725
super, thanks for your help in translating to use  INNER JOIN - a great help!
0
 

Author Comment

by:willsherwood
ID: 40474730
p.s.   just curious why something like this would "hang" mySQL for THIS database  when executed
 (other db were operational
during the period that this  query took hold of the the database)
0
 
LVL 58

Expert Comment

by:Gary
ID: 40474758
Could be several things without knowing the db setup. But a join is better than a nested select which involves more work.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now