mySQL query error SELECT? - mysql

I got this error when I'm trying a script.
mySQL query error: SELECT * FROM ibf_store_shopstock WHERE is_hidden='0' AND category=1 ORDER BY item_name ASC LIMIT 0,
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 '' at line 1
mySQL error code:
Date: Monday 23rd 2012f July 2012 05:37:44 PM`
This is odd, since the very same script I tried on my localhost (MySQL 5.5.14) works just fine, but when I try it on live server (MySQL 5.1.63), it results in this error. I thought there's no big difference between the MySQL version?
Anyway here is a part of the suspected script (it's quite long):
http://pastebin.com/YaQwVPqT

I think you are missing something after LIMIT clause "LIMIT start_record", "offset"
try
SELECT *
FROM ibf_store_shopstock
WHERE is_hidden='0' AND
category=1
ORDER BY item_name ASC
LIMIT 0, 10;

Related

A SQL with incorrect syntax does not thrown an error in MariaDB Server version: 10.1.45?

select distinct search_text,language, input_encode
from visitors
where unique_id='njZ3AWt7vmLcrGC2uOqnCplkm'
order by visitors_id desc
limit 9;
The above SQL is invalid. I get the following error when I run it on MySql Server version: 8.0.19
Your Recent searches:Error: Expression #1 of ORDER BY clause is not in SELECT list, references column 'visitors.visitors_id' which is not in SELECT list; this is incompatible with DISTINCT.
Makes sense.
But, when I execute the same SQL on Server version: 10.1.45-MariaDB guess what happens?
I get a result set. Can anyone explain how this could be?

SELECT LAST(CustomerName) AS LastCustomer FROM Customers;

I am beginner to mysql, while I practice syntax of LAST() i.e
SELECT LAST(CustomerName) AS LastCustomer FROM CUSTOMERS; I am getting an error.
Error : ERROR 1064 (42000): 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 '(CustomerName) AS LastCustomer FROM
CUSTOMERS' at line 1
the thing is there is nothing on mysql like LAST() function. You can see the comment here where it is said.
You can find the list of mysql functions visiting mysql aggregated functions
It is better to use simple query like the following -
SELECT CustomerName as LastCustomer ORDER BY id DESC LIMIT 1
Hope it helps...:)
Last() is not supported in Mysql so try
SELECT TOP 1 CustomerName FROM Customers ORDER BY CustomerID DESC;
try this
SELECT * FROM CUSTOMERS ORDER BY customer_id DESC LIMIT 1;

MySQL Getting the return of a substraction

We are trying to get the length of a physical exercise by using the timestamps on our sensor data.
We currently have the following query:
SELECT UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp DESC LIMIT 1)
- UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp ASC LIMIT 1)
AS output
(enters added for readability)
When testing this query in phpMyAdmin we get the following 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 'SELECT HAAS2.trainingsdata.timestamp FROM HAAS2.trainingdata
WHERE HAAS2.trainin' at line 1
We've tried different ways to write down the query all resulting in the same error. We don't understand where the syntax error lies.
SELECT max(UNIX_TIMESTAMP(timestamp)) -
min(UNIX_TIMESTAMP(timestamp)) AS output
FROM HAAS2.trainingdata
WHERE training_id = 1

sql query order by multiple CAST value int

i'm trying to run this in sql query, but not working. I tried single cast, it works fine, but when i tried to add two cast, it gives 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 'FROM useradvert WHERE optionsalerent='For sale' ORDER BY cast (rm as signed)' at line 1
This query below works.
SELECT * FROM popol WHERE optsale='For sale' ORDER BY cast(rm as signed) ASC
THis one doesn't work
SELECT * FROM popol WHERE optsale='For sale' ORDER BY cast(rm as signed) ASC, cast(salary as signed) ASC
I need to output both rm and salary rm. Both are integer values. Tqs in advance.

MySQL error 1064 (v 5.0.96) GROUP BY clause

I'm used to running on an Oracle database, so I'm not really quite sure how to trouble shoot this problem. I've narrowed down a simple example of my query to the following:
SELECT 0 as gm_rowID,
'-ALL Grantmakers-' as grantmakerName
FROM dual
GROUP BY 2
phpMyAdmin runs the SQL with the following 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 'ORDER BY 2 LIMIT 0, 30' at line 1
Oracle can run this query just fine. MySQL can run the query without the GROUP BY clause. Any ideas?
--Here is the entire query:
SELECT
p.grantmaker_rowid as gm_rowID,
gm.grantmaker_companyName as grantmakerName
FROM grantmaker_info gm, proposal_submission p
WHERE 0=0
AND p.grantmaker_rowid = gm.grantmaker_rowid
UNION
SELECT
0 as gm_rowID,
'-ALL Grantmakers-' as grantmakerName
FROM dual
ORDER BY 2
GROUP BY 2
LIMIT 0 , 30
Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using column
names, column aliases, or column positions. Column positions are
integers and begin with 1
From: http://dev.mysql.com/doc/refman/5.0/en/select.html
Unless you only have 1 column in that table, it should run fine. My suggestion however would be to reference the column name (or alias) of whatever you're trying to GROUP BY.
edit: My only other suggestion is to include the SHOW CREATE TABLE output for that table.
edit2: Ok I see you've updated your question. Why not instead of ORDER BY 2, you ORDER BY grantmakerName (if that's the column you want to order by?)