2009-07-09 89 views
3
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 

錯誤:這個mysql查詢有什麼問題?

Error Number: 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

回答

8

,你需要選擇的東西(一個表,說)

8

你錯過了 「FROM」 子句前的 「WHERE」。

SELECT app_contracts。*,app_customers.id作爲客戶,如app_boards.id板
FROM app_customers,app_contracts
WHERE app_customers.id = app_contracts.customer_id
AND app_boards.id = app_contracts.board_id
ORDER BY您的WHERE子句前app_contracts.id DESC

1

這一個必須工作:

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 
1

您還沒有指定從中選擇數據的表(一個或多個)。它應該是更加的形式:

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 

JOIN ...指定由三個表應當與按鍵。

3

沒有FROM子句