2014-06-29 39 views
-3

我试图做一个左与另一个选择加入,但我不断收到一个语法错误:SQL语法错误加盟

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 'LEFT JOIN (SELECT prediction_id, sum(value) from expenses as valoarea GROUP BY p' at line 3

SELECT id, name FROM `predictions` 
where `predictions` .tablet_id in (select id from tablets where user_id = 19) 
LEFT JOIN (SELECT prediction_id, sum(value) from expenses as expense_value GROUP BY prediction_id) ex 
ON `predictions`.id = `ex`.prediction_id; 

C和别人看看有什么错?谢谢!

回答

3

syntax of a SELECT queryJOIN到来之前WHERE

SELECT id, name FROM `predictions` 
LEFT JOIN (SELECT prediction_id, sum(value) from expenses as expense_value GROUP BY prediction_id) ex 
ON `predictions`.id = `ex`.prediction_id; 
where `predictions`.tablet_id in (select id from tablets where user_id = 19)