Solved

what wrong in mysql query syntax?

Posted on 2014-03-25
8
800 Views
Last Modified: 2014-03-25
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=?
0
Comment
Question by:KRUNAL TAILOR
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 39952828
Run your query in a MySQL client. The syntax looks fine.
0
 
LVL 12

Author Comment

by:KRUNAL TAILOR
ID: 39952856
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
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39952867
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=?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:ste5an
ID: 39952876
I would guess, it depends entirely what are you doing in your "node.js" code. Post a concise and complete example.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39953186
.....ParentId)) A order by categoryId",[dbid]
I don't really know node.js but I would assume that the problem might be that you are using 2 ? placeholders but are only providing 1 parameter.  Can you try this...
.....ParentId)) A order by categoryId",[dbid],[dbid]

Open in new window

0
 
LVL 12

Author Closing Comment

by:KRUNAL TAILOR
ID: 39955012
Thank you mccarl for your help.
0
 
LVL 12

Author Comment

by:KRUNAL TAILOR
ID: 39955013
Thanks for all, all of this information was very helpful.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39955014
Your welcome! :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question