What's the correct sql command to find exact matches?
-
02-06-2021 - |
Question
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."%'";
Solution
have you tried the =
operator and removing the %
wild cards?
OTHER TIPS
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."'";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow