2011-10-25 212 views
1

我有兩個表:MySQL的查詢需要幫助

t1 
------------------ 
inv_ID 
inv_memID 
inv_projID 

t2 
------------------ 
is_ID 
is_msgID 
is_contID 

我需要得到所有t2.is_contID到一個數組,其中

  • inv_projID = 5
  • t2.is_msgID = T1 .inv_ID和
  • t1.inv_memID = 1

似乎很簡單的,但我堅持......嘗試這樣:

SELECT t2.is_contID 
INNER JOIN t1 ON (t1.inv_ID = t2.is_msgID) 
FROM t2 
WHERE t1.inv_projID = 5 
AND t1.inv_memID = 1 

我缺少什麼?

回答

1

FROMJOIN之前。

SELECT t2.is_contID 
FROM t2 
INNER JOIN t1 ON (t1.inv_ID = t2.is_msgID) 
WHERE t1.inv_projID = 5 
AND t1.inv_memID = 1 

SQL對關鍵字的順序非常挑剔。
正確的順序是:

SELECT 
FROM 
JOIN 
WHERE 
HAVING 
GROUP BY 
ORDER 
LIMIT <<-- MySQL only, other DB's user other keywords in other places. 
+0

大新......我想編寫代碼,並從http://businessofsoftware.org/觀看現場直播形式的稀釋那些關注... – santa