views:

127

answers:

5
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

Error:

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  A: 

You're missing the "FROM" clause before the "WHERE".

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

Rich Adams
+7  A: 

you need to select FROM something (a table, say) before your WHERE-clause

David Hedlund
Doh !
Click Upvote
+1  A: 

This one must work:

 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
FerranB
+1  A: 

You haven't specified a table(s) from which to select the data. It should be more of the form:

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

Where JOIN ... specifies the keys by which the three tables should be related.

Alistair Knock
+3  A: 

There is no FROM clause

Justin Giboney
Its funny how 5 people posted the same answer and i upvoted all of them :p
Click Upvote