I'm using 5.1.41-3ubuntu12.10 for my MySQL version.
UPDATE profiledata SET aboutyou = '$aboutyou', quotes = '$quotes'
WHERE uid = '$sess_uid'
and
UPDATE profileprivacy
SET aboutyouPrivacy = '$aboutyouPrivacy', quotesPrivacy = '$quotesPrivacy'
WHERE uid='$sess_uid'
$sess_uid is the same for both. I was wondering if I could combine both MySQL queries into one mysql_query.
I was thinking it would be something like SET profiledata.aboutyou = 'Just a developer.'
, not really sure.
For instance, updating 2 different tables together in a single query/statement. This involves the use of the BEGIN TRANSACTION clause and the COMMIT clause. The individual UPDATE clauses are written in between the former ones to execute both the updates simultaneously.
In SQL Server, we can join two or more tables, but we cannot update the data of multiple tables in a single UPDATE statement.
First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.
We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required. we can use the following command to create a database called geeks.
You can use a join like this:
$query = "UPDATE profiledata t1
JOIN profileprivacy t2 ON (t1.uid = t2.uid)
SET t1.aboutyou = '$aboutyou',
t1.quotes = '$quotes',
t2.aboutyouPrivacy = '$aboutyouPrivacy',
t2.quotesPrivacy = '$quotesPrivacy'
WHERE t1.uid = '$sess_uid'";
MySQL does have multi-table update support: http://dev.mysql.com/doc/refman/5.0/en/update.html.
UPDATE profiledata, profileprivacy
SET aboutYou = ..., aboutyouPrivacy = ...
WHERE (profiledata.uid = $sess_uid) OR (aboutyouPrivacy.uid = $sess_uid)
or something similar should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With