2017-07-18 35 views
0

我需要從通過joins.every時間三個表得到具體列得到特定的列不言而喻wrong.my代碼從三個表

$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服務器版本相對應的手冊,以便在第1行的'Id = tpaidamount.pid和pod.Customer Id = follow.pid'附近使用正確的語法。

+1

已在「pod.Customer ID爲」一個空間,刪除客戶和Id – mulquin

+0

它的這種方式之間的空間在表 – user3111955

+0

使用反引號圍繞客戶ID,如果空間是列名。 – pritaeas

回答

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 
+0

請讓我檢查您的解決方案 – user3111955

+0

嗨,這可能是因爲Customer和Id之間的空間。嘗試使用''用於客戶ID。我已經更新了我的建議答案。 – louisecode

+0

是的,它的工作感謝 – user3111955

0

您不應該使用空格創建列名稱。名稱:「pod.Customer Id」是一個Bad屬性名稱,您需要避免使用名稱,如數據類型(或任何SGBD保留字),如'date','time','char','table','列」 .... 然而,如果你需要做的,試試這個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 queryes。例如:table_name AS tn,table_a_name AS tan。

  • !!!我吸收你觀看一些基本的SQL課程。 祝你好運。

+0

其不工作 – user3111955

+0

感謝您對屬性的建議。我改變了一切。 – user3111955