[英]SQL JOIN query error
好吧,所以我現在使用SQL已經有一段時間了..大概2也許3年了。 我會說我非常擅長,但是話雖如此,我還是無法完全理解SQL中的“ JOIN”功能。 教程和其他內容也無濟於事。
我今天一直在擺弄它,但我仍然無法使它工作。
<?php
include($_SERVER['DOCUMENT_ROOT'].'/includes/constants.php');
$sql = "UPDATE users SET health = store.type_value - health WHERE uid = :uid INNER JOIN store AS store WHERE iid = :iid";
$que = $db->prepare($sql);
$que->bindParam('uid', $_SESSION['uid']);
$iid = '1';
$que->bindParam('iid', $iid);
try{$que->execute();}catch(PDOException $e){ echo $e->getMessage(); }
?>
有人可以向我解釋如何糾正嗎?
如果你正在使用MySQL,那么join
推移上面set
的語句:
update users join
store
on users.uid = :uid and iid = :iid
set health = store.type_value - health;
這會將兩個條件都放在on
子句中。 但是,這是一個奇怪的情況,我懷疑這不是您真正想要的。 users
和stores
之間的聯接密鑰是什么?
如果您正在使用SQL Server,然后join
進去一from
后子句set
:
update users
set health = store.type_value - health
from users join
store
on users.uid = :uid and iid = :iid;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.