I just moved to mySQL 8 and have errors on queries that worked in mySQL 5 before.
I can get the query to work without the string matching part, where it just matches an interger field, but it errors when I add the string part.
Query: select * from crew where webvisible = 1 and active = 1 and rank = 'member'
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 '= 'member'' at line 1
I need to query based on the rank field where it is different string values like: member or member applicant, or stowaway, etc.
rank is a reserved word in MySQL 8+. You need to enclose it in backticks i.e.
select * from crew where webvisible = 1 and active = 1 and `rank` = 'member'
Related
i have a table and i have columns. I want to get AGE column- it is creating (current date - year column data)- and whole columns like *.
I tried;
SELECT (YEAR(CURRENT_DATE) - YEAR(dateOfBirth)) as age , * FROM users
but 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 users LIMIT 0, 25' at line 1
What should i write? Thank you!
use alias and TIMESTAMPDIFF function
SELECT u.*,
TIMESTAMPDIFF(YEAR, dateOfBirth, CURRENT_DATE) as age
FROM users u
'Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference' - https://dev.mysql.com/doc/refman/8.0/en/select.html
This is ok
SELECT (YEAR(CURRENT_DATE) - YEAR(dateOfBirth)) as age, users.* FROM users
SELECT (SUM(MAX(identifier)+1) FROM student_ids WHERE state ='state' AND year='year');
SELECT (SUM(MAX(identifier)+1) FROM student_ids WHERE state ='state' AND year='year')
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 'FROM student_ids WHERE state ='state' AND year='year')
LIMIT 0, 25' at line 1
how can i fix the error
The SUM function is for taking aggregates of columns, across multiple rows. You don't need to use it to add a scalar value:
SELECT MAX(identifier) + 1 AS max_id
FROM student_ids
WHERE state = 'state' AND year = 'year';
Additionnaly to #tim-biegeleisen, use ` for column names and table names, like this : `year`, `state`, ...
Because some words you uses are reserved. YEAR is reserved word and could return an error if you uses it as column name. SQL thinks you are calling the year function instead of a column named year.
SELECT MAX(`identifier`) + 1 AS `max_id`
FROM `student_ids`
WHERE `state` = 'state'
AND `year` = 'year' ;
Here is documentation about reserved words in mySQL :
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
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
MySQL query is
SELECT option as value, name as text from jos_components where parent = 0 and enabled=1 order by name
I have a table jos_components which have field name option. I want to run above query but it gives me an 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 'option as value, name as text from jos_components where parent = 0 and enabled=1' at line 1
What's the problem?
option is a MySQL reserved word. You'll have to surround it with backticks in your query. Try this:
SELECT `option` as value, name as text from jos_components where parent = 0 and enabled=1 order by name
why this will make an error?
$this->db->where('MATCH (title) AGAINST ("stackoverflow")', NULL, TRUE);
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 'AGAINST
("stackoverflow") LIMIT 4' at line 3
SELECT * FROM (table) WHERE MATCH
(title) AGAINST ("stackoverflow")
LIMIT 4
when change to FALSE,the query will ok,but i want to protect mytable with with backticks
Standard SQL uses single quotes, not double quotes.
MATCH (title) AGAINST ('stackoverflow')
You can test whether this is really the problem with a string as your WHERE clause.
$where = "MATCH (title) AGAINST ('stackoverflow') LIMIT 4";
$this->db->where($where);