Ne bu mysql sorgu ile yanlış?

5 Cevap php
SELECT app_contracts.*, app_customers.id as customer, app_boards.id as board
 WHERE app_customers.id=app_contracts.customer_id 
 AND app_boards.id=app_contracts.board_id 
 ORDER BY app_contracts.id DESC

Hata:

Hata Numarası: 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 'WHERE app_customers.id=app_contracts.customer_id AND app_boards.id=app_contracts' at line 2

5 Cevap

Eğer NEREDE fıkra önce bir şey (bir tablo, diyelim ki) DAN seçmeniz gerekir

Sen "WHERE" önce maddesi "DAN" kaçırıyorsun.

SELECT app_contracts.*, app_customers.id as customer, app_boards.id as board
FROM app_customers, app_contracts
WHERE app_customers.id=app_contracts.customer_id
AND app_boards.id=app_contracts.board_id
ORDER BY app_contracts.id DESC

Fıkra DAN Orada hiçbir

Bu bir işe gerekir:

 SELECT app_contracts.*, app_customers.id as customer, app_boards.id as board
 FROM app_customers, app_contracts, app_boards
 WHERE app_customers.id=app_contracts.customer_id 
 AND app_boards.id=app_contracts.board_id 
 ORDER BY app_contracts.id DESC

Siz verileri seçmek için bir tablo (s) belirlenmiş değil. Bu form daha fazla olmalıdır:

SELECT app_contracts.*, app_customers.id as customer, app_boards.id as board
FROM app_contracts, app_customers, app_boards
JOIN ...
WHERE app_customers.id=app_contracts.customer_id 
AND app_boards.id=app_contracts.board_id 
ORDER BY app_contracts.id DESC

Nerede JOIN ... üç tablo ilgili olmalıdır hangi anahtarları belirtir.