Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a problem, trying to sort my Select request -
SELECT * FROM `table_name` OREDER BY `score` DESC LIMIT 10 ;
I get error #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 'BY score DESC LIMIT 10' at line 1
But I realy don't know wats wrong ! Names and quotes are right, as I think... as this request works correctly:
INSERT INTO `table_name` (`uid`, `score`) VALUES ("'.$viewer_id.'","'.$uscore.'") ON DUPLICATE KEY UPDATE `score` = "'.$uscore.'";';
Can somebody help me!!??
P.S sorry for my English(
it's ORDER not OREDER
SELECT * FROM table_name ORDER BY score DESC LIMIT 10
As a sidenote, the query is vulnerable with SQL Injection if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.
How to prevent SQL injection in PHP?
You have a spelling error in your syntax it's 'ORDER BY' not 'OREDER BY' the correct syntax should be:
SELECT * FROM `table_name` ORDER BY `score` DESC LIMIT 10 ;
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a query which consists of both IN & NOT in the query but it gives me an error:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IN ('aniket27') ORDER BY id DESC LIMIT 2' at line 1
This is how my query looks
SELECT * FROM users
WHERE username IN ('aniket27','deepakrajak','bhawana','Mehul13','sanchayeeta',
'shivajidutta', 'anamika_4a','parekh','anupamkumar')
AND NOT IN ('aniket27')
ORDER BY id DESC LIMIT 2
You must specify column for NOT IN
SELECT * FROM users WHERE username IN ('...') AND username NOT IN ('aniket27') ORDER BY id DESC LIMIT 2
But first condition will be sufficient to match elements that are listed in NOT IN part, just remove them from first IN list.
You forgot to put the field name before "NOT IN" :
SELECT * FROM users WHERE username IN ('aniket27','deepakrajak','bhawana','Mehul13','sanchayeeta','shivajidutta','anamika_4a','parekh','anupamkumar') AND username NOT IN ('aniket27') ORDER BY id DESC LIMIT 2
try this:
SELECT * FROM users
WHERE username IN ('aniket27','deepakrajak','bhawana','Mehul13','sanchayeeta','shivajidutta','anamika_4a','parekh','anupamkumar')
AND username NOT IN ('aniket27')
ORDER BY id DESC LIMIT 2;
This question already has an answer here:
Mysql delete statement with limit
(1 answer)
Closed 8 years ago.
I have really searched this and find nothing about this problem.
Very simple query:
/*get rid of 125 rows starting at 100*/
delete from my_table WHERE category=5 order by editdate DESC LIMIT 100, 125;
This is what is returned:
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 ' 125' at line 1
I have not used LIMIT in a while, but at the same time I have not had a problem with it. Error is very mysterious, any ideas?
My version of mysql is 5.x
This is because the MySQL syntax for DELETE, doesn't allow a second parameter for LIMIT like in the SELECT case. Please check the manual.
You can't use a LIMIT offset on a DELETE command. Here's a way to do it:
delete from my_table WHERE ID IN (SELECT ID from my_table WHERE category=5 order by editdate DESC LIMIT 100, 150);
Where ID is the primary ID for my_table.
delete from my_table WHERE category=5 order by editdate DESC LIMIT 125;
This will work but you can't use limit like 100,125 . because it shows the selection between rows.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Using Mysql 5.5. Trying to use IF statement:
mysql> SELECT description IF(1=1,'ok','no') FROM my_table;
ERROR 1064 (42000): 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 'IF(1=1,'ok','no') FROM my_table at line 1
Ideas?
Correct syntax of IF() in mysql query is:
SELECT IF(condition, 'Some Result If True', 'Some Result If False'), OTHER_COLUMNS
FROM ...
WHERE ...
so you should use
SELECT description,IF(1=1,'ok','no') FROM my_table;
As a technical note, this is the if() function, not the if statement. In any case, you are just missing a comma:
SELECT description, IF(1=1,'ok','no')
------------------^
FROM my_table;
Assumming you want description ='yes' for 1=1 otherwise no
SELECT
CASE WHEN 1=1 THEN 'ok' ELSE 'no' END as description
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I wonder why my query isn't working, I am supposed to leave the WHERE 1 just as it is; I've used it like this many times before but for this query, it is not working.
SELECT * FROM industries WHERE 1 AND IN id (11,8,1,2,3,4,5,6) ORDER BY position ASC
Here is the error I get:
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 'IN id (11,8,1,2,3,4,5,6) ORDER BY position ASC LIMIT 0, 30' at line 1
SELECT * FROM industries WHERE id IN (11,8,1,2,3,4,5,6) ORDER BY position
Don't use WHERE 1 it does not make sense here. It is useless because it is evaluated as (always) true
And the correct syntax for IN is WHERE <column> IN (list)
SELECT * FROM industries WHERE 1 AND id IN (11,8,1,2,3,4,5,6) order by position;
This query should work:
SELECT * FROM industries WHERE id IN (11,8,1,2,3,4,5,6) ORDER BY position ASC
ASC is default, you can write just
ORDER BY position
This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
I've came across strange issue. I know I'm missing something very minor. Can Any One solve the problem plz.
This is my table:
cat_id name desc
1 Cricket Schedule
2 Live Cricket Live Cricket Desc
3 Fixtures
4 Videos
I ran following update query and worked fine.
UPDATE cats
set name='New Fixtures'
WHERE cat_id='3'
But When I Run Following Query, It returns error:
#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 'desc='New Fixtures Desc' WHERE cat_id='3'' at line 1
The Query is :
UPDATE cats
set desc='New Fixtures Desc'
WHERE cat_id='3'
Plz Tell me What I am Missing Here
desc is a reserved keyword, you must escape it with backtick
UPDATE cats
set `desc` = 'New Fixtures Desc'
WHERE cat_id = '3'
MySQL Reserved Keywords List