Solved

what wrong in mysql query syntax?

Posted on 2014-03-25
8
775 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 32

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
 
LVL 32

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Creating and Managing Databases with phpMyAdmin in cPanel.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now