Jürgen Paul
Jürgen Paul

Reputation: 15037

Find search term in multiple columns

How do you search for a term in multiple columns: title,content. For example:

$searchTerm = 'android';

SELECT * FROM posts WHERE `title` OR `content` contains $SearchTerm

Upvotes: 0

Views: 183

Answers (3)

Aniketos
Aniketos

Reputation: 659

SELECT 
  *
FROM 
  posts
WHERE
  lower(`title`) LIKE '%android%'
  OR lower(`content`) LIKE '%android%'

Upvotes: 1

hohner
hohner

Reputation: 11588

$sql = "SELECT * FROM posts WHERE `title` LIKE '%$SearchTerm%' OR `content` LIKE '%$SearchTerm%'";

Upvotes: 0

Emil Vikström
Emil Vikström

Reputation: 91983

SELECT *
FROM posts
WHERE
   `title` LIKE '%android%'
OR `content` LIKE '%android%'

Upvotes: 0

Related Questions