KRUNAL TAILOR
asked on
What's wrong in the mysql query with node.js?
Hi all,
I have node.js api with mysql. I am using the query below and it is working perfect,
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate gory.categ oryId as category FROM smaatz LEFT OUTER JOIN smaatzcategory ON smaatz.id = smaatzcategory.SmaatzId LEFT OUTER JOIN category ON smaatzcategory.CategoryId = category.categoryId where "+ (category?"category.catego ryId = "+category+" and":"")+" name like '%"+keyword+"%'"
when i try to modify it like this it is not working, what is wrong with this, any syntax mistake.
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate gory.categ oryId as category FROM smaatz LEFT OUTER JOIN smaatzcategory ON smaatz.id = smaatzcategory.SmaatzId LEFT OUTER JOIN category ON smaatzcategory.CategoryId = category.categoryId where extra2="dbid_private_demo_ cars" AND "+ (category?"category.catego ryId = "+category+" and":"")+" name like '%"+keyword+"%'"
The bold characters above added in syntax did i made wrong query?
Any kind of help appreciated.
Thanks & Regards,
Krunal T Tailor
I have node.js api with mysql. I am using the query below and it is working perfect,
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate
when i try to modify it like this it is not working, what is wrong with this, any syntax mistake.
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate
The bold characters above added in syntax did i made wrong query?
Any kind of help appreciated.
Thanks & Regards,
Krunal T Tailor
If extra2 does not represent character string but e.g. number then depends on dbid_private_demo_cars data type.
Let suppose dbid_private_demo_cars contains a string which represents data in the numeric extra2 column. In other words if it contains some number as a string then you may simply use + operator:
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate gory.categ oryId as category FROM smaatz LEFT OUTER JOIN smaatzcategory ON smaatz.id = smaatzcategory.SmaatzId LEFT OUTER JOIN category ON smaatzcategory.CategoryId = category.categoryId where extra2=" + dbid_private_demo_cars + " AND "+ (category?"category.catego ryId = "+category+" and":"")+" name like '%"+keyword+"%'"
If dbid_private_demo_cars is of the numeric data type then you have to convert it into a string before adding it to the query.
And the last possibility - the extra2 contains the string "dbid_private_demo_cars".. . Then you just need to enclose the hardcoded string to quotes:
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate gory.categ oryId as category FROM smaatz LEFT OUTER JOIN smaatzcategory ON smaatz.id = smaatzcategory.SmaatzId LEFT OUTER JOIN category ON smaatzcategory.CategoryId = category.categoryId where extra2= 'dbid_private_demo_cars' AND "+ (category?"category.catego ryId = "+category+" and":"")+" name like '%"+keyword+"%'"
Let suppose dbid_private_demo_cars contains a string which represents data in the numeric extra2 column. In other words if it contains some number as a string then you may simply use + operator:
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate
If dbid_private_demo_cars is of the numeric data type then you have to convert it into a string before adding it to the query.
And the last possibility - the extra2 contains the string "dbid_private_demo_cars"..
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Guy Hengel Thank you very much.
"SELECT id, name, downloads, description, Price, extra2, extra3, smaatzImage,smaatzUrl,cate
extra2 could also be qualified by table name, e.g. smaatz.extra2 (this is valid for all columns in the query)