Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

delete where exists ???

 
   Database Help (Home) -> mySQL RSS
Next:  obfuscate an integer and store in a number column  
Author Message
Rotsj

External


Since: Feb 09, 2005
Posts: 1



(Msg. 1) Posted: Wed Feb 09, 2005 4:40 pm
Post subject: delete where exists ???
Archived from groups: mailing>database>mysql (more info?)

Hi,

if i run the following query:
select *
from std_order_lines sol
where exists(select * from std_orders so, customers c
where so.customers_id = c.customers_id
and c.test_customer = 'Y'
and so.order_id = sol.order_id)

i get all the order_lines from test_customer 'Y'. I want to delete these
lines so i changed the query to:
delete
from std_order_lines sol
where exists(select * from std_orders so, customers c
where so.customers_id = c.customers_id
and c.test_customer = 'Y'
and so.order_id = sol.order_id)

unfortunately, i get error 1064 'check your syntax'. Is it not possible to
use this construction in a delete?

Rotsj

 >> Stay informed about: delete where exists ??? 
Back to top
Login to vote
Aggro

External


Since: Aug 28, 2003
Posts: 8



(Msg. 2) Posted: Wed Feb 09, 2005 4:40 pm
Post subject: Re: delete where exists ??? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rotsj wrote:

 > unfortunately, i get error 1064 'check your syntax'. Is it not possible to

See the syntax and examples in here and modify one for your needs:

<a rel="nofollow" style='text-decoration: none;' href="http://dev.mysql.com/doc/mysql/en/delete.html" target="_blank">http://dev.mysql.com/doc/mysql/en/delete.html</a>

 >> Stay informed about: delete where exists ??? 
Back to top
Login to vote
Bill Karwin1

External


Since: Jun 17, 2004
Posts: 42



(Msg. 3) Posted: Wed Feb 09, 2005 4:40 pm
Post subject: Re: delete where exists ??? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rotsj wrote:
 > delete
 > from std_order_lines sol
 > where exists(select * from std_orders so, customers c
 > where so.customers_id = c.customers_id
 > and c.test_customer = 'Y'
 > and so.order_id = sol.order_id)
 >
 > unfortunately, i get error 1064 'check your syntax'. Is it not possible to
 > use this construction in a delete?

Well, the subquery worked in your SELECT, so you're using MySQL 4.1
which is required for subqueries.

My guess is the use of a table alias in the FROM clause, and then using
that within the subquery.

I find that the following does not give a syntax error (but I didn't
verify that it deletes the correct rows Smile.

delete
from std_order_lines
where exists(select * from std_orders so, customers c
  where so.customers_id = c.customers_id
  and c.test_customer = 'Y'
  and so.order_id = std_order_lines.order_id)

Another suggestion would be to do this as a multi-table DELETE, since
EXISTS is equivalent to an inner join:

DELETE sol
FROM std_order_lines AS sol INNER JOIN std_orders AS so
ON sol.order_id = so.order_id
INNER JOIN customers AS c
ON so.customers_id = c.customers_id
WHERE c.test_customer = 'Y';

Regards,
Bill K.
 >> Stay informed about: delete where exists ??? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
delete dupes with a unique id using a temp table - I need to delete the dupes across bu's. The records are unique based on bu+ndc but there are 400+ duplicates.. There is a sequential id that is unique. I am trying to remove these 400+ records. 1. SELECT * FROM ci GROUP BY bu,ndc HAVING..

Best way to issue hundreds of inserts/updates??? - Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file and then have mysql do them all?? IE : query.txt insert..

MySQL freezes, brings XP machine to a grinding halt - I've been using MySQL for a while for fairly light database development on my XP machine. Currently, I am just starting a new project and have experienced some big problems with MySQL today both on my office machine and at home where running a particular...

login as user 'root' but do not have root privlages and my.. - Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it doesn't recognize me being logged in as root (via..

FLUSH TABLES hangs if table is locked - Using FLUSH TABLES via the C query API mysql_query() hangs if the table is locked already. That is to say, nothing prevents me from running a LOCK TABLES twice; it won't tell me "it's already locked, don't try to run a FLUSH". Anyone know ...
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]