Mysql SELECT with an OR across 2 columns
- by Haroldo
I'm creating a 'similar items' link table.
i have a 2 column table. both columns contains product ids. The table is showing that these items are similar. However ids in the left column are more valuable.
Say i want to select similar items to product '125b'. i only want 3 similar items to 125b. If there are any instances of 125b in col1 I would prefer these to finding 125b in col2.
so i need a select statement along the lines of
SELECT * FROM similar_items WHERE col_1={$id} OR col_2={$id} ORDER BY column(?) LIMIT 3
i do not want to do 2 separate queries ( ie query 2 if count(query1) <3 )