glennn.php Posted July 7, 2010 Share Posted July 7, 2010 i have a field, "models", which will contain an array such as "Acura, Camaro, Blazer" - i'm trying to learn how to use IN to get any row that would contain "Acura" within that field. SELECT * from TABLE WHERE 'Acura' IN 'models'...? that didn't work... anyone...? thanks much GN Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/ Share on other sites More sharing options...
trq Posted July 7, 2010 Share Posted July 7, 2010 Its generally a poor design that leads you to storing comma separated strings within a field. You should look at normalization techniques and give each of those delimited values its own row. Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/#findComment-1082480 Share on other sites More sharing options...
glennn.php Posted July 7, 2010 Author Share Posted July 7, 2010 very true. i'm not good at JOINS and multiple tables, especially when the client wants to pay budget scale... be that as it is, can you show me how i'd get Acura out of that array? i am in fact researching how i'd normalize this table - i hate to do a bad job even when the money isn't right. i'm much obliged... Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/#findComment-1082492 Share on other sites More sharing options...
trq Posted July 7, 2010 Share Posted July 7, 2010 IN isn't going to help, you'll need to use LIKE. SELECT * FROM tbl WHERE Models LIKE '%Acura%'; Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/#findComment-1082786 Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2010 Share Posted July 7, 2010 http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/#findComment-1082790 Share on other sites More sharing options...
glennn.php Posted July 8, 2010 Author Share Posted July 8, 2010 IN isn't going to help, you'll need to use LIKE. SELECT * FROM tbl WHERE Models LIKE '%Acura%'; that's waht i ended up doing, thanks - Quote Link to comment https://forums.phpfreaks.com/topic/207014-finding-a-value-in-a-field-which-contains-an-array/#findComment-1082955 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.