2010-07-06 80 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]';