PHP- how do you get SQL server to retrieve an EXACT match from a search?

travo

New member
This is my query to the server:
$search= CKR;
$query = "SELECT clubid FROM club WHERE clubid= '$search'";

It WILL retrieve all the "clubid's" from "club" that match "CKR." However, it also retrieves the "clubid's" that say "CKRA" or "CKRC".

I only want it to retrieve the data that says CKR exactly, nothing else.

Is there a way to write the query so SQL knows to only retrieve an EXACT match? Thanks!
 
Your query seems to be correct. The SQL query to select an exact match would be
SELECT clubid FROM club WHERE clubid = 'CKR';
If you needed an unexact match you would use like. Eg.
SELECT clubid FROM club WHERE clubid like '%CKR%';
 
Back
Top