本文介绍了一次更新两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用5.1.41-3ubuntu12.10作为我的MySQL版本.

I'm using 5.1.41-3ubuntu12.10 for my MySQL version.

UPDATE profiledata SET aboutyou = '$aboutyou', quotes = '$quotes'
WHERE uid = '$sess_uid'

UPDATE profileprivacy
SET aboutyouPrivacy = '$aboutyouPrivacy', quotesPrivacy = '$quotesPrivacy'
WHERE uid='$sess_uid'

$ sess_uid两者相同.我想知道是否可以将两个MySQL查询合并为一个mysql_query.

$sess_uid is the same for both. I was wondering if I could combine both MySQL queries into one mysql_query.

我当时想像是SET profiledata.aboutyou = 'Just a developer.'之类的东西,不是很确定.

I was thinking it would be something like SET profiledata.aboutyou = 'Just a developer.', not really sure.

推荐答案

您可以使用如下联接:

$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'";

这篇关于一次更新两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:14