SQL Query in XAMPP - mysql

SELECT * FROM customers WHERE Age > ALL (SELECT Age FROM customers WHERE Salary > 6800);
Actually I am trying to learn the usage of ALL in SQL. But unfortunately when I am trying to execute this query it's giving me the error in XAMPP.
Static analysis:
2 errors were found during analysis.
Unrecognized keyword. (near "ALL" at position 36) Unexpected token.
(near "(" at position 40) SQL query: Documentation
SELECT * FROM customers WHERE Age > ALL ( LIMIT 0, 25
MySQL said: Documentation
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 'LIMIT 0, 25' at line 1
I would like to know what is the exact syntactical error in my query.
Here's my Table:
Customer Table

There is nothing syntactically wrong with your query, you have an unfortunate version of phpMyAdmin which messes it up. The problem was present in 4.5.1, not present in 4.6.4, it was fixed some time in between.
This is the query that you send (OK):
SELECT * FROM customers WHERE Age > ALL (SELECT Age FROM customers WHERE Salary > 6800);
This is the query that server receives from phpMyAdmin (very wrong):
SELECT * FROM customers WHERE Age > ALL ( LIMIT 0, 25
Hence the problem.

Related

Query SELECT COALESCE(SELECT, ...) not working with MySQL 8.0

With MySQL 5 this query worked without any issue:
SELECT 1+COUNT(*) AS rank
FROM userpoints
WHERE points > COALESCE((SELECT points FROM userpoints WHERE userid=(SELECT userid FROM users WHERE handle='abc123' LIMIT 1)), 0)
With MySQL 8.0.23 it throws an error:
MySQL query error 1064: You have an error in your SQL syntax
Is it not allowed to "embed" SELECTs into other SELECTs anymore? See the userid=(SELECT... part.
Or is it a problem with COALESCE?

#1064 - You have an error in your SQL syntax - not exist - xampp

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

MySQL phpmyadmin - SELECT FOR UPDATE not recognised

I'm writing a PHP program and wanna to implement row-level locking to avoid concurrent user update/delete for the same record.
But I hit error "Unrecognised keyword" when using SELECT FOR UPDATE. Table type is innoDB.
Am i missing any setup for my database?
SELECT * FROM companyTable
WHERE companyId = "0000001"
FOR UPDATE;
Error
Static analysis:
1 errors were found during analysis.
Unrecognized keyword. (near "FOR" at position 57)
SQL query: Documentation
SELECT * FROM companyTable WHERE companyId = "0000001" FOR LIMIT 0, 30
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 'LIMIT 0, 30' at line 3
There Is an Syntax Error Try this:
Its Select All Records From 1 - 30
SELECT * FROM companyTable WHERE companyId = "0000001" ORDER BY id LIMIT 30;
First problem seems to be, that in your SQL query is missing keyword UPDATE
SELECT * FROM companyTable WHERE companyId = "0000001" FOR LIMIT 0, 30
And the second issue can be, that syntax SELECT ... FOR UPDATE in MySQL doesn't support LIMIT.
So your SQL query should be:
SELECT * FROM companyTable WHERE companyId = "0000001" FOR UPDATE
In phpmyadmin, it is difficult to remove auto added LIMIT clause - try another MySQL client.
PhpMyAdmin is not build to handle(Test) transaction control, use Mysql Console or php session instead
and use "begin" to start the Transaction before the code
begin;
select * from `tblx` where `idx`=1 for update;
update `tblx` set `field`='xx' where `idx`=1;
commit;

Not Able to Count Less/ Greater Than a Value in MySQL Table

I am trying to COUNT rows less or greater than 100 in MYsQL table using PHPMyAdmin
SELECT HAVING COUNT(`roadLength`) > 100 AS stop3 FROM `single-ecolo-dis-yes-tbl`
and
SELECT HAVING COUNT(`roadLength`)< 100 FROM `single-ecolo-dis-yes-tbl`
but I am getting this error
SELECT HAVING COUNT(`roadLength`) > 100 FROM `single-ecolo-dis-yes-tbl`
LIMIT 0, 25
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 'HAVING COUNT(`roadLength`) > 100 FROM `single-ecolo-dis-yes-tbl`
LIMIT 0, 25' at line 1
can you please let me know why this is happening? and how I can fix this?
having is to reduce the groups in a query and has no business in the select clause. It is a clause for itself
SELECT SUM(`roadLength` > 100) AS stop3
FROM `single-ecolo-dis-yes-tbl`
Normally, for a simple count like this, you would put the condition in the WHERE clause:
SELECT COUNT(*) as stop3
FROM `single-ecolo-dis-yes-tbl` t
WHERE t.roadLength > 100 ;
This allows the optimizer to use an index on roadLength, if one is available.

My sql syntax error 1064 -can't find what is wrong

I go this error message when I run this query
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
Error
SQL query: Documentation
SELECT name, state
FROM customers
WHERE state ‌IN(
'CA', 'NC', 'NY'
)
LIMIT 0 , 30
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 '‌in ('CA','NC','NY') LIMIT 0, 30' at line 1
I has a look there http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html but I still can't find the reason why
Thank you
Remove the = after IN
SELECT name, state FROM customers
WHERE state ‌IN ('CA','NC','NY')
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
You can not use the '=' with an IN
I tried to copy your query and run it in MySQL
You have some strange "hidden" character before IN
If you delete it, then everything works fine