MySQL Forums
Forum List  »  Perl

Re: Is it possible to use several statements in one query?
Posted by: Bill Karwin
Date: June 13, 2006 05:15PM

I can think of two options. You could do this with a multi-table UPDATE instead of subqueries:

UPDATE Table
JOIN Table2 ON Table.ID = Table2.TableID
JOIN Table3 ON Table.ID = Table3.TableID
JOIN Table4 ON Table.ID = Table4.TableID
JOIN Table5 ON Table.ID = Table5.TableID
SET
T2 = Table2.smth,
T3 = Table3.smth,
T4 = Table4.smth,
T5 = Table5.smth
WHERE ID=?

You can also set a user variable, and then use it in a subsequent statement, as long as you do both statements in the same database connection.

$h->do('SET @id = ?', {}, 100);
$h->do('UPDATE ... WHERE ID=@id');

Be careful about using double-quotes vs. single-quotes.
Perl interprets @id as an array variable if it's in a double-quoted string.

Regards,
Bill K.

Options: ReplyQuote


Subject
Written By
Posted
Re: Is it possible to use several statements in one query?
June 13, 2006 05:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.