I have a pretty difficult query to ask so I want to use the WITH ... AS syntax to break it down to smaller steps. I am trying to build a dummy query to ses how it works, which basically selects the stations that belong to a certain company and just selects everything again.
WITH company_stations AS (
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
) SELECT * FROM company_stations;
the inside query works fine on it's own
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
But when I use it Inside the with as statement it gives me the very helpful error message
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 'company_stations AS (SELECT stationName FROM Station WHERE Station.stationProvid' at line 1
I tried searching for the ERROR 1064 (42000) but it seems that everyone that faced this error was in the process of building, populating or accessing a DB. I have done all these things, but the specific query seems to be problematic.
Also I tried all the usual suspects such as ' or " or `, ( or no ( etc.
CTE expressions is not supported before MySQL 8.0
You can use sub-queries instead:
SELECT * FROM (
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
) AS company_stations;
Related
"Incorrect syntax" when using a common table expression
WITH a AS
(
SELECT *
FROM student_table_name
WHERE student_id=6639352
ORDER BY modified DESC
)
SELECT * FROM a
Error Code: 1064
You have an error in your SQL syntax
It works without the
(
)
SELECT * FROM a
but when im running the inner query everything works!
somehow the "with" command dont act like it should do..
I have made a sql statement that works normal in a shared server. but since I migrated the database to a local one
it showing a #1064 - You have an error in your SQL syntax
INSERT INTO shops (shop_name, googleid, address, city, country, open_now, logogroup, idshopgroup, shop_group, image, website)
select '$shopname', '".$key["googleid"]."','$address','".$key["city"]."',
'".$key["country"]."', '".$key["open_now"]."','".$key["logo"]."','".$key["groupid"]."','$groupname','".$key["photo_reference"]."', '".$key["website"]."'
WHERE NOT EXISTS (
SELECT googleid FROM shops WHERE googleid = '".$key["googleid"]."'
) LIMIT 1;
I fixed the problem by adding a "from 'tablename'" before the "WHERE" clause
The query that is throwing an error for my MySQL DB is:
SELECT t1.GROUPNAME FROM user_group t0, group t1 WHERE ((t0.users_USERNAME =
?) AND (t1.GROUPNAME = t0.groups_GROUPNAME))
The error info is the following:
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 t1 WHERE
((t0.users_USERNAME = 'test') AND (t1.GROUPNAME = t0.groups_GROUP')
Okay so I know the problem is with the group t1 part. But I dont know what is wrong with it.
Click here to see that I have all the needed colums
Can any one find out what the problem could be here?
group is a reserved word in SQL. You should put quotes around it.
Some JPA providers do that automatically, whereas others don't ...
I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
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 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here
I'm learning sql from these wikibooks pages and I'm trying to answer the last question "Remove all boxes from saturated warehouses" using mysql syntax. The following is what I came up with on my own mainly using previous answers from the same page.
delete from Boxes as b
where b.Warehouse in (
select w.Code
from ( select *
from Warehouses) as w
where w.Capacity < ( select count(*)
from Boxes bb inner join Warehouses ww
on bb.Warehouse = ww.Code
group by bb.Contents) ) ;
The query for this question on the site is generating
this solution doesn't work with mysql 5.0.67
ERROR 1093 (HY000): You can't specify target table 'Boxes' for update in FROM clause
That's why I'm using multiple sub queries as a way to come around this mysql message. However, I have an error in my query and therefore it's not running.
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 'as b where b.Warehouse in ( select w.Code
from ( sel' at line 1
Any idea?
I assume Boxes and Warehouse are tables, you gave Boxes an alias and used it on the Warehouse table, that's probably why it didn't work. Maybe you should try with a query after 'delete from'.
I think your warehouses table returns from than one columns (since * is used). Replace * with the column u want to get the output from.