My query statement
SELECT Count(DISTINCT name)
FROM facebook.users
results to
mysql.ProgrammingError: (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 '\xef\xbb\xbfSELECT Count(DISTINCT name)
\r\nFROM facebook.users' at line 1")
How do I fix this, thanks
You should check how you pass your query. \xef\xbb\xbf is UTF-8 BOM.
The UTF-8 representation of the BOM is the (hexadecimal) byte sequence 0xEF,0xBB,0xBF
SELECT Count(DISTINCT name) FROM facebook.users
-- query is correct
Related
I am trying to compare to characters using MySQL. I've tried this tow querys:
ASCII(SELECT SUBSTRING(column_name,1,1) FROM information_schema.columns WHERE table_schema='prac' AND table_name='Users' limit 1)>0;
(SELECT SUBSTRING(column_name,1,1) FROM information_schema.columns WHERE table_schema='prac' AND table_name='Users' limit 1 )like 'A%';
But both of them give me 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
If I execute the query without the comparation, like this
SELECT SUBSTRING(column_name,1,1) FROM information_schema.columns WHERE table_schema='prac' AND table_name='Users' limit 1;
It returns the first letter from the column name without problems.
Why when I try to compare it with the character or the ASCII value I get that error?
I have table named templog and I have a date column named 'tdate' which stores a string in the 'mm/dd/yy' format. I tried to convert using the following syntax but I receive an error.
SELECT convert(datetime,tdate,110) from templog
SQL query: Documentation
SELECT convert(datetime,tdate,110) from templog 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 'tdate,110) from templog LIMIT 0, 25' at line 1
Any ideas on what I'm doing wrong?
For MariaDB, you want str_to_date():
SELECT str_to_date(tdate, '%m/%d/%y')
FROM templog
I was trying to test out the strcmp() function with strings
containing random email addresses in this SQL statement:
INSERT IGNORE INTO possible_duplicate_email
-> (human_id, email_address_1, email_address_2, entry_date)
-> VALUES(LAST_INSERT_ID(), 'bobyfischer#mymail.com',
'bobbyfischer#mymail.com')
-> WHERE ABS( STRCMP('bobbyrobin#mymail.com', 'bobyrobin#mymail.com') ) = 1;
Then I got this 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 'WHERE ABS( STRCMP('bobbyrobin#mymail.com',
'bobyrobin#mymail.com') ) = 1' at line 4
I've read the strcmp() documentation from the mysql-5.7 reference manual
and tried a simple SELECT statement to see that strcmp() returned a numeric
value ranging -1, 0, 1, which it did, and I've included the IGNORE option
to the SQL statement so as to proceed through errors. Could someone explain to me why I get this error when running strcmp() in the WHERE clause?
Thanks to Paul T., the answer is:
INSERT statements do not have a WHERE clause, unless doing an INSERT ... SELECT statement, then the SELECT portion of the query can use a WHERE clause.
I am trying to do a select query on MySQL with phpMyAdmin or PHP with PDO.
SELECT 'uid' FROM 'clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' AND 'lng'>='22.90243'
However, phpMyAdmin says:
#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 ''clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' A' at line 1
What is wrong with it?
'' creates a string literal in MySQL, so your query is selecting the literal "uid" from the literal "clusters," which is invalid. Use backtics (or nothing)
SELECT Uid FROM clusters WHERE lat <= 47.21125 AND lat >= 39.21125
AND lng >= 22.90243
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).