Jump to content

Backwards wildcard on column? Can it be done?


tunnelboy

Recommended Posts

SELECT * FROM database WHERE col1 LIKE '%foo%';

Simple. But I've got to do this backwards. In my col1 database, I have values like this:

pk col1
1 Joe
2 Susan
3 Richard|Joe
4 Jane|Sam|Steve
5 Gloria|Joseph

My search criteria is coming from another database of SINGLE NAMES, so I want to do this:

SELECT * FROM database WHERE '%col1%' LIKE 'Joe';

And I want to return keys 1,3 & 5. I've tried the above, I've tried '%'+col1+'%'. Neither work.

Thanks

Link to comment
Share on other sites

If the problem is that you have multiple names in the column then you need to fix it by not storing multiple names in the column. Probably with a new table.

pk | database_id | name
---+-------------+-----
 1 |           1 | Joe
 2 |           2 | Susan
 3 |           3 | Richard
 4 |           3 | Joe
 5 |           4 | Jane
 6 |           4 | Sam
 7 |           4 | Steve
 8 |           5 | Gloria
 9 |           5 | Joseph

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.