2010-07-06 111 views
0

我想加入2個帶有ID的表格。我寫了下面的查詢,但我得到一個錯誤。我想在mysql中同時選擇所有列。加入查詢問題

select t1.* t2.* table1t1 
    JOIN table2t2 
    ON t1.id = t2.postads_id 
where ads_id=1277719543 
    AND email='[email protected]'; 

ERROR: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1 JOIN nextpostads t2 ON t1.id = t2.postads_id where ads_id=1277719543 AND emai' at line 1

需要哪些修改?

+0

什麼是兩個表的表結構? – NotMe 2010-07-06 13:27:59

回答

4

有一個逗號丟失t1.*t2.*之間並沒有FROM條款:也

SELECT t1.*, t2.* 
    FROM table1 t1 
    JOIN table2 t2 
    ON t1.id = t2.postads_id 
WHERE ads_id = 1277719543 
    AND email = '[email protected]' 

,儘量堅持所有關鍵字或小寫字母的大寫,但不相混合。

+0

查詢解決謝謝大家:) – saurav 2010-07-06 13:38:34

+1

如果解決了它,你應該接受它作爲正確的答案。你應該如何處理你的大部分其他問題。這樣,人們就會知道哪個答案是正確答案(並且答案是正確的)。 – 2010-07-06 14:01:42

0

您在聲明中遺漏了FROM。 嘗試:

select t1.*, t2.* 
FROM table1 t1 
    JOIN table2 t2 
    ON t1.id = t2.postads_id 
where ads_id=1277719543 
    AND email='[email protected]'; 
+0

SELECT t1。 * t2。 * FROM T1 postads JOIN T2 nextpostads ON t1.id = t2.postads_id WHERE ads_id = 1277719543 及email = '[email protected]' LIMIT 0,30 MySQL表示: #1064 - 你必須你的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以找到在'附近'使用的正確語法。 * FROM postads t1 JOIN nextpostads t2 ON t1。 id = t2。 postads_id where ads_i'at line 1 我現在正在接受這個錯誤.. – saurav 2010-07-06 13:32:47

0
select t1.*, t2.* FROM table1 t1 
    JOIN table2 t2 
    ON t1.id = t2.postads_id 
where t1.ads_id=1277719543 
    AND t1.email='[email protected]';