简体   繁体   English

SQL查询错误#1064

[英]SQL query error#1064

This is the query I wrote: 这是我写的查询:

SELECT students.name, subjects.sub
FROM students INNER JOIN (subjects INNER JOIN test ON subjects.IDsub = test.IDsub) ON  students.IDstu = test.IDstu
WHERE ((test.date)=#1/21/2013#);

Everytime I execute this query I get this message: 每次执行此查询时,都会收到以下消息:

'#1064 - You have an error in your SQL syntax; '#1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 30' at line 4 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第4行的“ LIMIT 0,30”附近使用

I think the problem is in the date format because if I execute this one: 我认为问题出在日期格式上,因为如果执行此命令,则:

SELECT students.name, subjects.sub
FROM students INNER JOIN (subjects INNER JOIN test ON subjects.IDsub = test.IDsub) ON students.IDstu = test.IDstu
WHERE ((test.IDsub)=4);

Everything works fine! 一切正常!

In the database there are 3 tables: "students", "test", "subjects". 数据库中有3个表:“学生”,“测试”,“主题”。

date should be like this, ie instead of # make use of ' 日期应该像这样,即代替#使用'

SELECT students.name, subjects.sub
FROM students INNER JOIN 
(subjects INNER JOIN test ON subjects.IDsub = test.IDsub) 
  ON  students.IDstu = test.IDstu
WHERE ((test.date)='1/21/2013');

str_to_date str_to_date

SELECT students.name, subjects.sub
FROM students INNER JOIN (subjects INNER JOIN test ON subjects.IDsub = test.IDsub) ON  students.IDstu = test.IDstu
WHERE ((test.date)=str_to_date('1/21/2013');

The other issue I see is that the use of the pound sign # is not a valid way to create a string lookup in mysql. 我看到的另一个问题是井号#的使用不是在mysql中创建字符串查找的有效方法。 You want to use the single quote ' 您要使用单引号'

PhpMyAdmin adds a snippet of SQL to each command to limit the number of records returned. PhpMyAdmin向每个命令添加一个SQL代码段,以限制返回的记录数。

LIMIT 0, 30

I'd remove the semicolon from the end of your query, because otherwise, SQL thinks this extra snippet is another query. 我将从查询末尾删除分号,因为否则SQL会认为此额外的代码段是另一个查询。

WHERE ((test.date)=#1/21/2013#)

Also, I've never seen the # symbol used in a query like that, you might have a problem there. 另外,我从未见过像这样的查询中使用过# ,您那里可能有问题。

Edit: According to everyone else (who ignored the actual SQL Error...), the # is not valid, use quotes instead. 编辑:根据其他人(他们忽略了实际的SQL错误...), #无效,请使用引号。

Another Edit: Actually, the # notation seems valid. 另一个编辑:实际上, #符号似乎有效。

Select query with date condition 选择具有日期条件的查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM