tunnelboy Posted October 14, 2021 Share Posted October 14, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313988-backwards-wildcard-on-column-can-it-be-done/ Share on other sites More sharing options...
requinix Posted October 14, 2021 Share Posted October 14, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/313988-backwards-wildcard-on-column-can-it-be-done/#findComment-1591022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.