这个mysql查询有什么问题?

时间:2021-09-05 21:17:55
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

错误号码: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

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第2行的'WHERE app_customers.id = app_contracts.customer_id AND app_boards.id = app_contracts'附近使用正确的语法

5 个解决方案

#1


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

你需要在WHERE子句之前选择FROM something(一个表,比方说)

#2


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

您在“WHERE”之前缺少“FROM”子句。

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

SELECT app_contracts。*,app_customers.id作为客户,app_boards.id作为董事会来自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

#3


There is no FROM clause

没有FROM子句

#4


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

#5


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.

其中JOIN ...指定三个表应该相关的键。

#1


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

你需要在WHERE子句之前选择FROM something(一个表,比方说)

#2


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

您在“WHERE”之前缺少“FROM”子句。

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

SELECT app_contracts。*,app_customers.id作为客户,app_boards.id作为董事会来自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

#3


There is no FROM clause

没有FROM子句

#4


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

#5


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.

其中JOIN ...指定三个表应该相关的键。