tags:

views:

64

answers:

4

for example i use following command to find a record

SELECT `users`.`mail` 
  FROM `users` 
 WHERE `users`.`uid` = %s

if found an match, then i should like to delete this record, and update in the same query an another table. i can solve this with 'joins' ?

+1  A: 

No, there's no way to do three separate operations in one query.

Why do you need to do it in one?

Chad Birch
And if there was a way, you wouldn't want to use it ... I have the same question as Chad ("why?").
Smandoli
i thought when I use all in one query then I get a better performance 
mewis
@mewis: Inside the same transaction, rather than query, is the proper terminology.
OMG Ponies
@OMG Ponies: Okay, thank you.
mewis
+3  A: 

if found an match, then i should like to delete this record, and update in the same query an another table. i can solve this with 'joins' ?

Not with a single SQL query, no.

But you could perform those actions, using separate SQL queries, within a single stored procedure. This would be faster than submitting three queries separately from your application, because there's no time/performance lost transferring data back and forth over the wire (to and from your application code).

OMG Ponies
You know your username cracks me up every time. But then again I still go "horsie" when I see them in a field as I'm driving by.
HLGEM
And just for the moment we are all horsies of one kind or another, thanks I presume to an April Fools Day joke from SO.
Smandoli
A: 

I think the only reason you would want to select, then delete, is if you are doing it yourself and want to make sure you are deleting the right things. Something like

DELETE users.mail FROM users WHERE users.uid = %s

will return 0 if it deleted no rows, or a number of rows it deleted. You could just check the return and make a decision based on that as to what to update...

alkaloids
+1  A: 

If your goal is to improve performance you can do it using a single CALL to the DB using a store procedure that does 2 different queries inside.

munissor