我有一個MySQL的要求,那是工作的罰款:我如何使用WHERE加入左邊?
$pdo = $db->query('
SELECT *,
GROUP_CONCAT(cat.name SEPARATOR " <br> ") AS dog,
monkey.id AS id,
duck.id AS horse_id,
bird.id AS elephant_id
FROM monkey
LEFT JOIN duck ON monkey.horse=duck.id
LEFT JOIN bird ON monkey.elephant=bird.id
LEFT JOIN cat ON monkey.id=cat.mouse_id
GROUP BY monkey.id ASC;');
但現在我想選擇其中猴=「ID」僅值。
所以我試圖使這個解決方案:
$pdo = $db->query('
SELECT *,
GROUP_CONCAT(cat.name SEPARATOR " <br> ") AS dog,
monkey.id AS id,
duck.id AS horse_id,
bird.id AS elephant_id
FROM monkey WHERE id = "'.$id.'"
LEFT JOIN duck ON monkey.horse=duck.id
LEFT JOIN bird ON monkey.elephant=bird.id
LEFT JOIN cat ON monkey.id=cat.mouse_id
GROUP BY monkey.id ASC;');
但我得到這個錯誤:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 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 'LEFT JOIN duck ON monkey.chorse=duck.id LEFT JOIN bird ON monkey.bir' at line 7 in ..mypage.php:28 Stack trace: #0 ..mypage.php(28): PDO->query('\nSELECT *, \nGRO...') #1 {main} thrown in ...mypage.php on line 28
如有疑問,請檢查[語法](https://dev.mysql.com/doc/ refman/5.5/EN/select.html)。 select語句有一個特定的順序。 – aynber