It is better to store json data in a affiliate_phone_id field or use separate table to normalise it?
For example:
mysql> select * from phone;
+----+----------+-------------+-------------------------------------------------------------------------------------------+
| id | name | description | affiliate_phone_id |
+----+----------+-------------+-------------------------------------------------------------------------------------------+
| 32 | iPhone 5 | faster CPU | [{"affiliate_id":2,"affiliate_phone_id":123},{"affiliate_id":3,"affiliate_phone_id":222}] |
+----+----------+-------------+-------------------------------------------------------------------------------------------+
The data above show that each retailer have own Phone ID, for instance:
Company 2 (affiliate_id = 2), their Phone ID is 123
or would it be better to do seperate table something like this:
mysql> select * from phone_affiliate;
+----+----------+--------------+--------------------+
| id | phone_id | affiliate_id | affiliate_phone_id |
+----+----------+--------------+--------------------+
| 1 | 32 | 2 | 123 |
| 2 | 32 | 3 | 222 |
+----+----------+--------------+--------------------+
Or any other better suggestion?
Normalized table.
Perhaps, you don’t need “id” field in phone_affiliate table. You can set primary key (phone_id, affiliate_id) or (phone_id, affiliate_id, affiliate_phone_id), it depends on relations between data.