Solved

mysql DELETE  "gets stuck"

Posted on 2014-12-01
6
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Creating and Managing Databases with phpMyAdmin in cPanel.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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