如何使用内部联接更正搜索代码?

时间:2014-07-09 05:28:30

标签: sql

帮助请问...如何更正此代码?

SELECT Products.ProductID, Products.Name, Categories.CatName, " +
       "Products.Description, Products.Price FROM Products INNER JOIN Categories ON " +
       "Products.CatID = Categories.CatID ORDER BY Products.Price DESC WHERE " + column + " LIKE '%" + keyword + "%'";

2 个答案:

答案 0 :(得分:0)

order by应该在where子句

之后
"SELECT Products.ProductID, Products.Name, Categories.CatName, " +
"Products.Description, Products.Price FROM Products INNER JOIN Categories ON " +
"Products.CatID = Categories.CatID " +
"WHERE " + column + " LIKE '%" + keyword + "%'";
"ORDER BY Products.Price DESC"

正如其他评论所说,您应该考虑使用SQLParameters来避免 SQL注入

答案 1 :(得分:0)

您想要的反注入SQL代码?

如下:

"SELECT Products.ProductID, Products.Name, Categories.CatName, " +
"Products.Description, Products.Price FROM Products INNER JOIN Categories ON " +
"Products.CatID = Categories.CatID WHERE " + column + 
"LIKE CONCAT('%'," + keyword + ",'%')" +
"ORDER BY Products.Price DESC";