简体   繁体   中英

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; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 30' at line 4

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".

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

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. You want to use the single quote '

PhpMyAdmin adds a snippet of SQL to each command to limit the number of records returned.

LIMIT 0, 30

I'd remove the semicolon from the end of your query, because otherwise, SQL thinks this extra snippet is another query.

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.

Another Edit: Actually, the # notation seems valid.

Select query with date condition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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