MySQL Syntax With Simple Joins - mysql

I'm having trouble figuring out why this query does not work. Names have been sanitized as this is proprietary code.
QRY:
SELECT l.albert, o.ben, m.caleb, m.dennis, m.edgar
FROM octopus o, lorax l, monkey m
WHERE o.ben = l.ben
AND l.franklin= m.franklin
AND o.ben= :ben
ORDER BY l.albert DESC
LIMIT 1
Here is the error that I get:
MySQL 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 'QRY: SELECT l.albert, o.ben, m.caleb, m.dennis, m' at line 1

It seems like you have
"QRY: "
at the beginning of your query. It should start with
"SELECT ...

Related

Syntax Error with ASC, DESC with MySQL 8.0

I recently migrated my clients legacy infrastructure which entailed moving there old MySQL 5.0 database into a MySQL 8.0 database (We had some other issues while migrating to Server 2016 that meant we had to do this)
Anyway the client has contacted me today as one of there queries is not working and I can't get to the bottom of it.
It appears as if the following line is used on most / nearly all queries are not working.
GROUP BY L.GrowerID, L.DCropID, C.Variety, C.Crop, L.SizeID DESC, S.Size;
Full Query:
SELECT Cu.Customer, L.DCropID, C.Crop, C.Variety, D.Clone, G.Grower,
S.Size, SUM(L.EndTubers) AS "Tubers", FORMAT(SUM(L.EndWeight),2) AS "Weight"
FROM PotatoLabels.Crop C, PotatoLabels.PLabel2012 L, PotatoLabels.Sizes S,
PotatoLabels.DCrop D, PotatoLabels.Customers Cu, PotatoLabels.Growers G,
PotatoLabels.mmGrades M
WHERE (D.DCropID > 96534 AND Cu.CustomerID = 9 AND G.GrowerID = 1 )
AND L.CustomerID = Cu.CustomerID
AND D.DCropID = L.DCropID
AND C.CropID = D.CropId
AND L.SizeID = S.SizeID
AND L.GrowerID = G.GrowerID
GROUP BY L.GrowerID, L.DCropID, C.Variety, C.Crop, L.SizeID DESC, S.Size;
If I remove
GROUP BY L.GrowerID, L.DCropID, C.Variety, C.Crop, L.SizeID DESC, S.Size;
It comes back with completely blank results but it does run with no syntax errors.
Also worth mentioning, if I remove the ASC and (or) DESC the query runs without ascending & descending filtering applied - Which is slightly better not not sufficient for my client.
Please see below syntax errors I receive when using some of the faulting queries.
[Err] 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, S.Size' at line 12
[Err] 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 'ASC, L.SizeID DESC WITH ROLLUP' at line 22
I am no MySQL expert this has merely landed on my desk... I'm sure you understand.
Any help would be great.

last query result

SELECT sma_quotes.customer as name,
sma_quotes.date as date,
sma_quotes.selecttype as type,
sma_quotes.biller_id as bl_id,
sma_quotes.volume as volume,
sma_quotes.containernumber as cn_no,
sma_quotes.grand_total as total,
sma_sales.paid as paid
FROM sma_quotes
JOIN sma_sales ON sma_sales.quote_id = sma_quotes.id
WHERE name IS 'Everbest Foods'
Error
SQL query: Documentation
MySQL said: Documentation
#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 ''Everbest Foods' LIMIT 0, 25' at line 1
There is no LIMIT in your query, so the error message is suspicious.
However, you want =, not IS:
WHERE sma_quotes.customer = 'Everbest Foods'

MySQL syntax error when using sqlite3 query

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

#1064 When Deleting item from Table

I recently upgraded to MYSQL 5. That is latest version that webhost allows. When trying to update a table or delete an entry this is the error I receive while in phpmyadmin.
Error
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unclosed quote # 101
STR: '
SQL: DELETE FROM inmates WHERE inmates.counties_id = 33 AND CONVERT(inmates.link USING utf8) = \'http://inmate1.riversidesheriff.org/iis/\' LIMIT 1
SQL query:
DELETE FROM inmates
WHERE `inmates`.`counties_id` = 33
AND CONVERT(`inmates`.`link` USING utf8) = \'http://inmate1.riversidesheriff.org/iis/\'
LIMIT 1
MySQL said:
Documentation #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 '\'http://inmate1.riversidesheriff.org/iis/\' LIMIT
1' at line 1
and here is the query
SELECT * FROM `inmates` WHERE 1
any help is greatly appreciated
thank you.
Lose the backslash before the single-quotes: they are not required.
By that I mean, change this:
\'http://inmate1.riversidesheriff.org/iis/\'
To this:
'http://inmate1.riversidesheriff.org/iis/'

MySQL Error "right syntax to use near '/*100,3), '%') AS `Percentage` FROM INFORMATION_SCHEMA.PROFILING"

I got this weird error after trying to execute a query on a large table:
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 '/*100,3),
'%') AS Percentage FROM
INFORMATION_SCHEMA.PROFILING WHERE
QUERY_ID=' at line 1
What does it mean?
EDIT == this is the query
update cities w, states s set w.region_id = s.id
where s.code = w.region and w.country_id = s.country_id
The cities table has around 3 million entries and the states table around 6000
Just for the record I executed this query using a mysql client Navicat.
SQL supports C-style comments:
/* ... */
so it looks like /*100,3 is being interpreted as the beginning of a comment and that comment is wrecking the syntax of the rest of the SQL.