我需要通过连接从三个表中获取特定列。每次出错。我的代码是
$saf=mysqli_query($db , "select pod.mobile, tpaidamount.Aptdate, follow.cent, pdate, time from pod,tpaidamount, follow where tpaidamount.pid = follow.pid and pod.Customer Id = tpaidamount.pid and pod.Customer Id =follow.pid ");
$i=1;
while($sfg=mysqli_fetch_assoc($saf) or die(mysqli_error($db)))
;
?>
pod,tpaidamount,follow are tables and other coloumns
获取错误 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便使用“Id = tpaidamount.pid”和“pod.Customer Id = follow.pid'”附近的正确语法。在第1行
答案 0 :(得分:0)
这是一个错字吗?是setfollowup.pid还是follow.pid?
select pod.mobile, tpaidamount.Aptdate, follow.cent, <table>.pdate, <table>.time
from pod, tpaidamount, follow
where tpaidamount.pid = follow.pid
and pod.`Customer Id` = tpaidamount.pid
and pod.`Customer Id` = follow.pid
答案 1 :(得分:0)
您不应该创建带空格的列名。名称:&#34; pod.Customer Id&#34;是一个错误的属性名称,您需要避免使用数据类型(或任何SGBD保留字)之类的名称,如:&#39; date&#39;,&#39; time&#39;,&#39; char&#39; ,&#39;表&#39;,&#39;列&#39; .... 但是,如果您需要这样做,请尝试以下SQL:
SELECT p.mobile
, t.Aptdate
, f.cent
, ???.pdate
, ???.`time`
FROM pod AS p
JOIN tpaidamount AS t ON o.`Customer Id` = t.pid
JOIN follow AS f ON t.pid = f.pid ON p.`Customer Id` = f.pid
使用别名可以轻松编写SQL查询。例如:table_name AS tn,table_a_name AS tan。
!!!我很高兴你看一些基本的SQL课程。 祝你好运。