andresfz87 Posted June 6, 2012 Share Posted June 6, 2012 I have a table named PRODUCTS with 3 columns for three different categories, i want to select all products which have any of the 3 values in any of the 3 columns. What i'm trying to do is show related products based on any of the 3 categories. Example table: id,name,cat1,cat2,cat3 1,Keyboard,2,8,4 2,Mouse,2,NULL,NULL 3,Monitor,16,2,NULL Let's supose i'm viewing ITEM id=1, i want to do a query to show the other 2 products that have category number 2 in any of the 3 columns. How do I do that? Thank you very much, Andres Quote Link to comment https://forums.phpfreaks.com/topic/263776-mysql-how-to-compare-multiple-columns-for-matching-categories/ Share on other sites More sharing options...
Barand Posted June 6, 2012 Share Posted June 6, 2012 SELECT name FROM product WHERE 2 IN (cat1, cat2, cat3) Quote Link to comment https://forums.phpfreaks.com/topic/263776-mysql-how-to-compare-multiple-columns-for-matching-categories/#findComment-1351737 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.