在 MySQL 中加入两个子查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4701144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:20:14  来源:igfitidea点击:

Join two subquery in MySQL

sqlmysqljoin

提问by Howard

I am having problem in joint two subqueries in MySQL, e.g.

我在 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;

ERROR 1064 (42000): 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 'join (select * from table1 where id = 2)' at line 1

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

Is my syntax incorrect?

我的语法不正确吗?

采纳答案by Wazy

Check out some examples

查看一些示例

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);