Link to home
Start Free TrialLog in
Avatar of KRUNAL TAILOR
KRUNAL TAILOR

asked on

what wrong in mysql query syntax?

Hi all,

I need help to fix the MySQL query. I am using this query with node.js technology.

'Select * from (select categoryId,categoryName,categoryImage,smaatzCount,"YES" as SubCategoryAvailable from (Select categoryId, categoryName, categoryImage, coalesce(Count,0) as smaatzCount from category left join (SELECT count(SmaatzId) as Count, CategoryId as catId from smaatzcategory group by CategoryId) as tt on category.categoryId = tt.catId Where category.ParentId is Null) as categories where categoryId in (select ParentId from category) union all select categoryId,categoryName,categoryImage,smaatzCount,"NO" as SubCategoryAvailable from (Select categoryId,categoryName,categoryImage,coalesce(Count,0) as smaatzCount from category left join (SELECT count(SmaatzId) as Count, CategoryId as catId from smaatzcategory group by CategoryId) as tt on category.categoryId = tt.catId Where category.ParentId is Null) as categories where not exists (select ParentId from category where categories.categoryId = category.ParentId)) A order by categoryId'

Open in new window


the above query works perfect but when i tried below query it throws error like this_
"Error: ER_PARSE_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 '? AND category.ParentId is Null) as categories where not exists (select ParentId' at line 1"

New query:

"Select * from (select categoryId,categoryName,categoryImage,smaatzCount,'YES' as SubCategoryAvailable from (Select categoryId, categoryName, categoryImage, coalesce(Count,0) as smaatzCount from category left join (SELECT count(SmaatzId) as Count, CategoryId as catId from smaatzcategory group by CategoryId) as tt on category.categoryId = tt.catId Where category.DBID=? AND category.ParentId is Null) as categories where categoryId in (select ParentId from category) union all select categoryId,categoryName,categoryImage,smaatzCount,'NO' as SubCategoryAvailable from (Select categoryId,categoryName,categoryImage,coalesce(Count,0) as smaatzCount from category left join (SELECT count(SmaatzId) as Count, CategoryId as catId from smaatzcategory group by CategoryId) as tt on category.categoryId = tt.catId Where category.DBID=? AND category.ParentId is Null) as categories where not exists (select ParentId from category where categories.categoryId = category.ParentId)) A order by categoryId",[dbid]

Open in new window


Here [dbid] is passed value for category.DBID=?
Avatar of ste5an
ste5an
Flag of Germany image

Run your query in a MySQL client. The syntax looks fine.
Avatar of KRUNAL TAILOR
KRUNAL TAILOR

ASKER

Thanks ste5an

ya on client it is working fine but when i tried with node.js api it throws the above error. Some syntax error. but i am not getting where i made mistake.

Thanks & Regards,
Krunal T. Tailor
The error message seems to indicate you are passing in a parameter which I don't see in your code, notice the "near ?" in that error message.

But the sql you have provided does not contain that parameter.

Where/how does this apply?
     Here [dbid] is passed value for category.DBID=?
I would guess, it depends entirely what are you doing in your "node.js" code. Post a concise and complete example.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you mccarl for your help.
Thanks for all, all of this information was very helpful.
Your welcome! :)