Karan Gandhi
Karan Gandhi

Reputation: 1494

How do I search two columns?

I have a table with First Name, Last Name and Contact Number.

If user enters kar, then I want a full list with results containing kar in the First name or Last Name.

Upvotes: 3

Views: 64

Answers (3)

ChiragKM
ChiragKM

Reputation: 21

select firstname from table
where firstname like '%name%'

Upvotes: 0

bhamby
bhamby

Reputation: 15450

This assumes that kar is a portion of a name, if it is the full name, then do first_name = 'kar'

SELECT first_name, last_name, number
FROM your_phone_book
WHERE first_name LIKE '%kar%'
   OR last_name LIKE  '%kar%'

Upvotes: 1

Danny Beckett
Danny Beckett

Reputation: 20838

It's really rather simple:

SELECT * FROM directory
WHERE firstname LIKE '%kar%'
OR lastname LIKE '%kar%';

Upvotes: 1

Related Questions