steveangelis Posted August 16, 2009 Share Posted August 16, 2009 I have a headache of a query I am trying to write but I cannot seem to make it do what I want it to do: select userid,username,membergroupids,lastvisit from user WHERE FIND_IN_SET('146,', membergroupids) AND FIND_IN_SET('$id1', membergroupids) or FIND_IN_SET('$id2', membergroupids) order by username asc This query is doing exactly what it shows but not what I want. What I want it to do is get all the data with 146 in it that ALSO contain either $id1 or $id2 but what it is getting is everyone that has 146 and in $id1 but also, everyone that is just in $id2. Does anyone know how to fix it? This is what it should do: everyone = 146+$id1 everyone = 146+$id2 This is what it is doing: everyone = 146+$id1 everyone = $id2 Link to comment https://forums.phpfreaks.com/topic/170536-find_in_set/ Share on other sites More sharing options...
Hybride Posted August 16, 2009 Share Posted August 16, 2009 Just throwing this out there (never used FIS before), but it might be a parenthesis issue? Try: select userid,username,membergroupids,lastvisit from user WHERE FIND_IN_SET('146,', membergroupids) AND (FIND_IN_SET('$id1', membergroupids) or FIND_IN_SET('$id2', membergroupids)) order by username asc Link to comment https://forums.phpfreaks.com/topic/170536-find_in_set/#findComment-899552 Share on other sites More sharing options...
steveangelis Posted August 16, 2009 Author Share Posted August 16, 2009 No it is not. It is a problem with the and and or's in it all and where and when to place them. Link to comment https://forums.phpfreaks.com/topic/170536-find_in_set/#findComment-899562 Share on other sites More sharing options...
PFMaBiSmAd Posted August 16, 2009 Share Posted August 16, 2009 Did you actually try what Hybride posted? If you want - WHERE a AND (b OR c) your have to write it like he posted to override the built-in operator precedence. Link to comment https://forums.phpfreaks.com/topic/170536-find_in_set/#findComment-899577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.