watercolour watercolour - 3 months ago 4x
SQL Question

Selecting rows where phrase is in different columns

I've tried finding an answer to this, but I've had no luck.

I want to select all rows that contain a string

in at least one column.

This is my SQL query right now:
SELECT * FROM catalog WHERE name LIKE '%$search%'

I'd like to search some of the other columns (brand, model, category, subcategory, stock, year) as well as the name column. Is there any way I can search all of these columns in one SQL query?

SELECT * FROM catalog 
WHERE name LIKE '%$search%' 
  OR brand LIKE '%$search%' 
  OR model LIKE '%$search%'
  OR category LIKE '%$search%'
  OR subcategory LIKE '%$search%'
  OR stock LIKE '%$search%'
  OR year LIKE '%$search%'

You just need an OR condition so that as long as at least one of the columns you'd like to match meets your search requirement.