user3244268
user3244268

Reputation: 3

Find two firstnames in a database as part of full name column

Yo.

I want to find two first names such as 'name1' 'name2' in a column which contains both firstname and lastname.

WHERE ContactName IN ('name1%', 'name2%'); <-- doesn't work with wildcards

How do I do it?

Upvotes: 0

Views: 62

Answers (5)

jmail
jmail

Reputation: 6134

you should refer this link CLICK HERE:

.......WHERE ContactName LIKE 'name1 %' OR ContactName LIKE 'name2 %';

Upvotes: 0

Sadikhasan
Sadikhasan

Reputation: 18600

Try this

SELECT * FROM tbl_name 
        WHERE ContactName LIKE "name1%" OR ContactName LIKE "name2%";

Upvotes: 0

Jim
Jim

Reputation: 22646

One alternative is to list each individually and use LIKE

WHERE ContactName LIKE 'name1 %' OR ContactName LIKE 'name2 %';

Note that I've added a space after the name. I assumed you want an exact match on the first name.

Alternatively you could use MySQL REGEXP function:

WHERE ContactName REGEXP '^(name1|name2)$'

Upvotes: 1

Sumit Gupta
Sumit Gupta

Reputation: 2192

try

where Match(ContactName ) Against ('name1', 'name2') 

but before that make sure that you have Full text Index created on name field.

Upvotes: 1

blue
blue

Reputation: 1949

... WHERE ContactName LIKE "name1%" OR ContactName LIKE "name2%";

Upvotes: 0

Related Questions