mapleleaf Posted February 27, 2010 Share Posted February 27, 2010 I am trying to get this to work: SELECT * FROM articles WHERE (SELECT * FROM articles WHERE theme_id = 10 OR FIND_IN_SET(9, second_theme)) AND name = 'john' AND deleted = 'No' My error is: Operand should contain 1 column(s) What is the way around this? This query is dynamic in that multiple ANDS are sometimes added. Link to comment https://forums.phpfreaks.com/topic/193576-using-or-and-and-together/ Share on other sites More sharing options...
ignace Posted February 27, 2010 Share Posted February 27, 2010 SELECT * FROM articles WHERE theme_id = 10 AND name = 'John' AND deleted = 'No' AND find_in_set(9, second_theme) is not null Link to comment https://forums.phpfreaks.com/topic/193576-using-or-and-and-together/#findComment-1019079 Share on other sites More sharing options...
mapleleaf Posted March 1, 2010 Author Share Posted March 1, 2010 Getting an odd error with this. SELECT * FROM articles WHERE FIND_IN_SET(32, second_theme) AND deleted = 'No' //gives 16 rows SELECT * FROM articles WHERE theme_id = 34 AND deleted = 'No' //gives 13 rows SELECT * FROM articles WHERE theme_id = 34 OR find_in_set(32, second_theme) AND deleted = 'No' //gives 32 rows because 3 of the rows have 'Yes' for deleted. SELECT * FROM articles WHERE theme_id = 34 AND find_in_set(32, second_theme) IS NOT NULL AND deleted = 'No' //gives 13 rows so basically excludes all the second_theme I want to to be able to do the OR and then the AND conditions should be applied the results of the OR. Tx Link to comment https://forums.phpfreaks.com/topic/193576-using-or-and-and-together/#findComment-1020004 Share on other sites More sharing options...
mapleleaf Posted March 2, 2010 Author Share Posted March 2, 2010 SELECT * FROM articles WHERE (theme_id = 34 OR find_in_set(32, second_theme)) AND deleted = 'No'; Is what I needed. Link to comment https://forums.phpfreaks.com/topic/193576-using-or-and-and-together/#findComment-1020599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.