Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search two columns?

Tags:

sql

t-sql

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.

like image 342
Karan Gandhi Avatar asked Mar 01 '26 00:03

Karan Gandhi


2 Answers

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%'
like image 103
bhamby Avatar answered Mar 03 '26 12:03

bhamby


It's really rather simple:

SELECT * FROM directory
WHERE firstname LIKE '%kar%'
OR lastname LIKE '%kar%';
like image 27
Danny Beckett Avatar answered Mar 03 '26 13:03

Danny Beckett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!