What's the correct sql command to find exact matches?

北城余情 提交于 2019-12-13 23:16:00

问题


The below code will obviously search for similar results as the query variable but what is the SQL command to search for exact results and not "like"?

$query = "SELECT languages.language FROM languages WHERE language LIKE '%".$name."%'";

回答1:


have you tried the = operator and removing the % wild cards?




回答2:


Edit: Although I answered what you asked, it is worth pointing out, as others have said, that your code is vulnerable to SQL injection attacks :)

For exact matches:

$query = "SELECT languages.language FROM languages WHERE language ='".$name."'";

For non matches:

$query = "SELECT languages.language FROM languages WHERE language <> '".$name."'";


来源:https://stackoverflow.com/questions/10252513/whats-the-correct-sql-command-to-find-exact-matches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!