MySQL Forums
Forum List  »  Newbie

Re: difficulty in making a search with a choice of certain categories
Posted by: Phillip Ward
Date: November 13, 2017 06:17AM

Having multiple values ("1,3,") in a single field is a really Bad Idea.

Read up about Data Normalisation.

select * from Products ; 

+----+-------------------+  
| id | name      | price | 
+----+-------------------+  
|  1 | product 1 |   100 | 
|  2 | product 2 |   110 | 
|  3 | product 3 |   120 | 
+----+-------------------+  

select * from Categories ; 

+----+---------------+ 
| id | category_name | 
+----+---------------+ 
| 11 | category A    | 
| 22 | category B    | 
+----+---------------+ 

select * from Category_Products ; 

+--------+--------+ 
| cat_id | pro_id | 
+--------+--------+ 
|     11 |      1 | 
|     11 |      3 | 
|     22 |      2 | 
|     22 |      3 | 
+--------+--------+

Regards, Phill W.

Options: ReplyQuote




Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.