Getting error in phpmyadmin stored procedure script - mysql

Im creating a stored procedure in phpmyadmin, which get the event category list. The condition im using, im sending a parameter 'e_range' where i get the list on the basis of whatever i set the range on this parameter 3, 4 etc. but im getting an error in while executing this script:
#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 'e_range; else select category_id, category_name, category_thumb from category' at line 4
CREATE PROCEDURE `sp_category_list`(IN e_range int)
BEGIN
if(e_range != 0 or null) then
select category_id, category_name, category_thumb from category_list order by category_name limit e_range;
else
select category_id, category_name, category_thumb from category_list order by category_name;
END if;
END$$
Now problem is that, this script working good in my localhost pc. but im getting these error on my webserver CPANEL's phpmyadmin.
the MySQL keyword 'LIMIT' is not taking the value through parameter. or maybe not recognizing it. but when i remove this parameter from the select command and set the static number on this, it will work:
select category_id, category_name, category_thumb from category_list order by category_name limit 5;
now what is the procedure, so i will get the list through my given parameter.
Thank you :)

Related

query not working only when inside WITH ... AS statement

I have a pretty difficult query to ask so I want to use the WITH ... AS syntax to break it down to smaller steps. I am trying to build a dummy query to ses how it works, which basically selects the stations that belong to a certain company and just selects everything again.
WITH company_stations AS (
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
) SELECT * FROM company_stations;
the inside query works fine on it's own
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
But when I use it Inside the with as statement it gives me the very helpful 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 'company_stations AS (SELECT stationName FROM Station WHERE Station.stationProvid' at line 1
I tried searching for the ERROR 1064 (42000) but it seems that everyone that faced this error was in the process of building, populating or accessing a DB. I have done all these things, but the specific query seems to be problematic.
Also I tried all the usual suspects such as ' or " or `, ( or no ( etc.
CTE expressions is not supported before MySQL 8.0
You can use sub-queries instead:
SELECT * FROM (
SELECT * FROM Station WHERE Station.stationProvider = 'olympia_odos'
) AS company_stations;

#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

getting mysql Error 1064

I am build a basic application with golang, i am using github.com/go-sql-driver/mysql driver. I am connecting to clearDB mysql on heroku but every time i'm getting
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 'desc, price from product where id = ?' at line 1
I can't under stand why, this is the piece of code that i'm using for the query the product database.
id := c.Param("id")
row := db.QueryRow("select id, desc, price from product where id = ?;", id)
err := row.Scan(&product.Id, &product.desc, &product.price)
desc is a keyword so you get in trouble when you also named a column desc.
With MySQL you need to quote the name with backticks, like so:
"select id, `desc`, price from product where id = ?"

Why am I receiving "Unknown column 'xyz'" with WHERE clause on View SELECT query?

MySQL database (community) version: 5.6.27, Windows 7 Pro x64
I've just created this View:
DELIMITER $$
ALTER ALGORITHM=UNDEFINED DEFINER=`admin`#`%` SQL SECURITY DEFINER VIEW `vw_qb_assembly_component_info` AS (
SELECT
`qb_assembly_components`.`assembly_item_id` AS `assemblyId`,
`ai`.`name` AS `assemblyName`,
`qb_assembly_components`.`component_quantity` AS `componentQuantity`,
`qb_assembly_components`.`component_item_id` AS `item_id`,
`ci`.`name` AS `name`,
`ci`.`item_number_type` AS `item_number_type`,
`ci`.`type` AS `type`
FROM ((`qb_assembly_components`
JOIN `qb_items` `ai`
ON ((`ai`.`item_id` = `qb_assembly_components`.`assembly_item_id`)))
JOIN `qb_items` `ci`
ON ((`ci`.`item_id` = `qb_assembly_components`.`component_item_id`))))$$
DELIMITER ;
I am attempting to query the view for rows with a certain qb_assembly_components.assembly_item_id value. I've tried several variations of defining the column in the WHERE clause but always receive error:
Unknown column 'xyz' in 'where clause'
The following are the versions I've tried:
WHERE `qb_assembly_components`.`assemblyId` = 'RR-0T056'
WHERE `qb_assembly_components`.`assembly_item_id` = 'RR-0T056'
WHERE `assemblyId` = 'RR-0T056'
I'm stumped. I've googled a bit and found a few results that seem to suggest using the alias is the way to go (my last example in the above 3 examples) but it's not working.
What am I doing wrong?
If you are select from VIEWvw_qb_assembly_component_info``
then the where clause should refer to the view name (and not to the orginal table name)
WHERE `vw_qb_assembly_component_info`.`assemblyId` = 'RR-0T056'

mysql query seems to be error.can i select the updated column with one query

There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem.
ERROR: Unclosed quote # 173
STR: "
update voucher_nos
set (select voucher_type as points from vouchers where id='1') = points+1
where company_id = '24'
and finance_year='01/01/2014-01/01/2015';
update voucher_nos
set (select voucher_type as points from vouchers where id='1') = points+1
where company_id = '24'
and finance_year='01/01/2014-01/01/2015'";
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 voucher_type as points from vouchers
where id='1') = points+1 w' at line 1
helps will be appreciated
and finance_year='01/01/2014-01/01/2015'";
You have an unneccesary " at the end here, which is probably causing the Syntax error.
--
The second problem is that the first part of a SET statement should be a column name, not a value (or a query which returns one). But I'm not sure how to fix that unless you explain a bit more what you're trying to accomplish.