sKunKbad Posted May 3, 2010 Share Posted May 3, 2010 I'd like to be able to check a product_categories table and a products table for sub-categories and products of a category, and while my query is working, I'm not allowed to use UNION because supposedly we may have problems if we go with something other than MySQL. (not that we would, but that's the theory) SELECT category_id FROM `product_categories` WHERE parent_id =2 UNION SELECT product_id FROM `products` WHERE category_id =2 My options are: left, right, outer, inner, left outer, and right outer. I'm not a MySQL superstar, so if anyone can suggest a simple query that doesn't use UNION I would appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 I'm not following you....you're saying you can NOT use union syntax because you MUST use MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052658 Share on other sites More sharing options...
sKunKbad Posted May 3, 2010 Author Share Posted May 3, 2010 No, I'm not allowed to use UNION, because it's not part of the Active Record DB class (part of the CodeIgniter framework) that we are using. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052668 Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 Run two queries or screw the theory and run raw SQL query. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052672 Share on other sites More sharing options...
sKunKbad Posted May 3, 2010 Author Share Posted May 3, 2010 Run two queries or screw the theory and run raw SQL query. Yes, I could run two queries... I'm just always trying to do as little queries as possible. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052679 Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 UNION is actually running two queries anyway. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052681 Share on other sites More sharing options...
sKunKbad Posted May 3, 2010 Author Share Posted May 3, 2010 UNION is actually running two queries anyway. Didn't know that. That makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/200601-not-allowed-to-use-union/#findComment-1052690 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.