floridaflatlander Posted February 21, 2011 Share Posted February 21, 2011 I have a test sql query like the one below that works fine SELECT columns FROM table2, smf_members WHERE table2.id_member = smf_members.id_member AND smf_members.id_group = '9' ORDER BY member_name; However smf has group membership in a column called id_group and a column called additional_groups which holds CSVs. Can I write a SELECT query and change smf_members.id_group = '9' to query both the id_group column and the additional CSVs column for a group #. I need this to print out a table using while loop. Quote Link to comment https://forums.phpfreaks.com/topic/228406-how-do-you-get-info-from-a-mysql-comma-separated-value-column-using-sql/ Share on other sites More sharing options...
ignace Posted February 21, 2011 Share Posted February 21, 2011 Would this help? SELECT columns FROM table2 JOIN smf_members ON table2.id_member = smf_members.id_member WHERE smf_members.id_group = '9' OR find_in_set('9', smf_members.additional_groups) ORDER BY member_name FIND_IN_SET() Quote Link to comment https://forums.phpfreaks.com/topic/228406-how-do-you-get-info-from-a-mysql-comma-separated-value-column-using-sql/#findComment-1177864 Share on other sites More sharing options...
floridaflatlander Posted February 21, 2011 Author Share Posted February 21, 2011 It worked like a charm. I tried to just add AND smf_members.id_group = '9' OR find_in_set('9', smf_members.additional_groups) and I couldn't get it to work. I just added AND find_in_set('9', smf_members.additional_groups) and it only pulled from the one (csv)column. I put your sql code in and it worked, Thanks S Quote Link to comment https://forums.phpfreaks.com/topic/228406-how-do-you-get-info-from-a-mysql-comma-separated-value-column-using-sql/#findComment-1177898 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.