web application got a error mysql query - mysql

select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2"
I got a error in this:
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

Error #1064 means that MySQL can't understand your command. To fix it:
Read the error message. It tells you exactly where in your command
MySQL got confused.
Check the manual. By comparing against what MySQL
expected at that point, the problem is often obvious.
Check for reserved words. If the error occurred on an object identifier, check
that it isn't a reserved word (and, if it is, ensure that it's
properly quoted).
You need to remove the quotes at the end and run your query. Looks like there is a typo, you intended a ; instead.
select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2;

Related

Simple SQL update query not working

I need to run this query but I get an error:
UPDATE wp_usermeta
SET meta_value = "a:1:{s:16:\"client_special\";b:1;}"
WHERE user_id = "1009";
But I get this 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 'UPDATE wp_usermeta
SET meta_value = "a:1:{s:16:\"cliente_especial\";b:1;}" W' at line 1
It is ok for me, I escaped the " with \ character.
As you discovered, and as my comment alluded, non-printing or hidden characters in your SQL statement can lead to unexpected syntax errors.
When confronted with what appears to be ludicrous messages, I find carefully retyping the statement into a different program helps decide whether it is a hidden character issue or a legitimate syntax issue.
It is the act of careful retyping that sanitizes the statement and rules out the non-printing characters. More than once I've done this and I imagine I will continue to do this for the rest of my career!

Error while updating inMySQL

I am working with MySQL and I am facing issues while updating the below command:
UPDATE group_access_mst SET
access='0',view='0',add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE role_id='1' AND page_id='1';
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 'add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE
role_id='1' AND p' at line 1
If I remove add,delete from the quesry it works fine!!
Is there any way i can make these command to work. I can understand that in MySQL ADD,DELETE,SELECT,INSERT are commands so it is not working.
In this case i need to change the fields names?
You should enclose the field names within back quote:
UPDATE group_access_mst
SET `access`='0',
`view`='0',
`add`='0',
`modify`='0',
`delete`='0',
`save`='0',
`xl`='0',
`import`='0'
WHERE role_id='1'
AND page_id='1';

Mysql search and replace when involving "http://"

I'm trying to search and replace in MYSQL but get an error. I'm quessing it's because of the "http://"
Anyone got any suggestions when trying replace this type of thing?
Code entered:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
But it throws 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 '://movie’, ‘http://www.movie’)' at line 1
Posting so it can be accepted:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
contains smart quotes, which are not interpreted as normal single quotes, thus the syntax error. It should instead be
update movies_news set select_page = replace(select_page, 'http://movie', 'http://www.movie');
In general, be really careful about copying code to and from 'smart' text editors (Microsoft Word, etc)

Workbench doesn't allow delete table

I have a table newsletter and I want to delete/update/insert data in it, but when I type
delete * from crm_base.newsletter
for example, it gets an red "X" in the line and gives me the following error message:
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 '* from crm_base.newsletter_temp' at line 1.
I already unchecked the safe update mode in preferences and resetted workbench, but it still gives me the same error.
Can anyone help me?
delete from crm_base.newsletter
Your syntax is not correct, use DELETE FROM crm_base.newsletter WHERE condition. Check the Delete syntax reference.

SQL Syntax Error; Query looks valid and works on other tables

I recently added a new table to my database and am getting the following error when I attempt a delete.
DELETE FROM usage WHERE date='2011-07-26';
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 'usage where date='2011-07-26'' at line 1
EDIT: Turns out usage is a reserved word. See this link for reserved words:
http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html
Try:
DELETE FROM `usage` WHERE `date` = '2011-07-26';
Escape your table names with a back tick (`) to avoid the clashing with reserved words. USAGE is a reserved word in this case.