I am writing a PHP script where I will search for a keyword in a specific table and return the id of that keyword.
What I have done so far is:
SELECT * FROM 'table' WHERE column_name LIKE '%keyword%'
This returns the entire row of the keyword. What I want is a query that will just return the id of that row, so I can put it in a variable.
First, you should probably replace the quotes around
'table'with backticks, or you’ll likely get syntax errors somewhere. The rest of my query examples use backticks for the table name. It’s advised to use them for column names too to reduce the chance of conflicts.Instead of using
*to fetch all columns, explicitly list which columns you want to fetch:The
*wildcard selects all columns as you have noticed from your original query.If you want to select other columns, list them as comma separated names: