SQL syntax error in Mysql table [duplicate] - mysql

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 6 years ago.
I'm trying to run the query
select * from Order;
I m getting the following syntax error in sql fiddle.
Could not figure out the correct syntax.
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 'Order' at line 1
http://sqlfiddle.com/#!9/aee9e/62

Order is a MySQL reserved word. Change your query to use backticks:
select * from `Order`;

Order is a reserved keyword for mysql refer to this link;
Simply change your table name from Order to orders.
Bye!

Related

Please help - mysql query problems [duplicate]

This question already has answers here:
How do you use the "WITH" clause in MySQL?
(7 answers)
Closed 6 years ago.
I want to use a SQL Query with the WITH clause an I get a Syntax Error.
I´m using MySQL Version 5.6.28
Here a simple Code example
WITH alias_test AS (SELECT id, title FROM `tips_locations`)
SELECT id, title
FROM alias_test
Here the error I get in my SQL Tool
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 'alias_test AS (SELECT id, title FROM tips_locations) SELECT
id, title FROM ali' at line 1
Can you Help me?
MySQL doesn't support WITH clause or CTE and thus the error. Alternative, you can either use a temporary table or a normal table like
CREATE TEMPORARY TABLE alias_test AS
SELECT id, title FROM `tips_locations`;
SELECT id, title
FROM alias_test;

How to choose a table that has the table name : "group"? [duplicate]

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 last month.
I have a table. Name of the table is "group"
I run query like this:
SELECT * FROM GROUP
There exist error like this:
Error Code: 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 'group
LIMIT 0, 1000' at line 1
Any solution to solve my problem?
use backquote :
SELECT * FROM `GROUP`
you can also alias your table name for later use in WHERE clause for instance:
SELECT * FROM `GROUP` g WHERE g.id = 1

MySQL Update Query Not Working For Different Columns [duplicate]

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

MySql - Can't sort a varchar column? [duplicate]

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'm trying to do a really simple sort on a varchar column, and I get a syntax error. Tested both with PHP and phpmyadmin.
This is the query:
SELECT * FROM cards_available_properties ORDER BY option
this is the error:
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 'option LIMIT 0, 30' at line 1
OPTION is a reserved keyword. escape it with backtick.
SELECT * FROM cards_available_properties ORDER BY `option`
MySQL Reserved Words

does the existence of an asterisk in a select exclude other columns?

This question is all about laziness... I'd like to do something like this:
select some_func(some_col), * from my_table
So that I don't have to do this:
select some_func(some_col), col_1, col_2... col_ad_infinitum from my_table
Is there any way to make the first query work? This is the error I get when I run it:
ERROR 1064 (42000) at line 1: 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 '* from my_table' at line 1
Do you mean that in MySQL your first query:
SELECT some_func(some_col), *
FROM my_table
produces this error?:
Error Code: 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 '*' at line 1
You can change your code into (this results in no errors!):
SELECT *, some_func(some_col)
FROM my_table
or into this, if you want to have the calculated columns first:
SELECT some_func(some_col), t.*
FROM my_table AS t
Unfortunately, mysql only supports the asterisk at the start of the column list (unlike every other DB I am familiar with)
(Edited: start not end - oops!)
Change the order of your select params:
select *,some_func(some_col) from my_table
Anyway, as the Zen of Python says: "Explicit is better than implicit". Always try to write the fields you're selecting, and if it's posible try to put the table they're from too, you can use an alias. Your future YOU will thank you.
select t.some_col from my_table t
When I do that with PostgreSQL, I get the column(s) I specify followed by all the other columns (possibly repeating the column(s) I specified).