Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join two subquery in MySQL

Tags:

sql

join

mysql

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

(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

Is my syntax incorrect?

like image 614
Howard Avatar asked Jan 15 '11 17:01

Howard


1 Answers

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);
like image 106
Wazy Avatar answered Oct 09 '22 10:10

Wazy