Reputation: 499
I'm trying to use a query to narrow the table down to only the rows in which the field [full name] contains the value in the field [first name].
For instance, if a row has "Blake Johnson" in [full name] and "John" in [first name] - this row will be included. But if [full name] has "Garry Sways" and [first name] has "Swan" - this row will NOT be included.
I tried to use:
Like "*[first name]*"
In the criteria for [full name].
But it didn't work quite well.
Is there a "Contains" funciton for this case?
Thanks in advance.
Upvotes: 2
Views: 7005
Reputation: 3226
Just do this
SELECT * From yourTable WHERE instr(fullname, firstname) > 0
Upvotes: 2
Reputation: 15755
I am not sure what kind of query language you are using but you can use regular expressions to make a more granular version of "like"
For example, in MySql you can do:
SELECT * FROM 'foo' WHERE 'bar' REGEXP "^\$"
or in your case:
SELECT * FROM table WHERE fullname REGEXP (".*" + firstname + ".*");
Upvotes: 0