在MySQL中加入两个子查询

时间:2011-01-15 17:50:25

标签: sql mysql join

我在MySQL的联合两个子查询中遇到问题,例如

(select * from table1 where id = 1 group by f1) a1 
join 
(select * from table2 where id = 2 group by f2) a2 ON  a1.f3 = a2.f3;

错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行“join(select * from table1 where id = 2)”附近使用正确的语法

我的语法不正确吗?

1 个答案:

答案 0 :(得分:2)

查看一些示例

SELECT * FROM table1, table2;

SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;

SELECT * FROM table1 LEFT JOIN table2 ON table1.id=table2.id;

SELECT * FROM table1 LEFT JOIN table2 USING (id);