What are the potential pitfalls of storing comma-separated values in a single column in a database table?

Storing comma-separated values in a single column in a database table can make it difficult to query and manipulate the data efficiently. It can lead to issues such as difficulty in searching for specific values, lack of data integrity, and limited ability to perform operations like sorting or joining tables. To solve this issue, it is recommended to normalize the database by creating separate tables for the related data and establishing proper relationships between them.

// Example of normalizing the database by creating separate tables

// Table for storing main data
CREATE TABLE main_data (
    id INT PRIMARY KEY,
    name VARCHAR(50)
);

// Table for storing related data
CREATE TABLE related_data (
    id INT PRIMARY KEY,
    main_data_id INT,
    value VARCHAR(50),
    FOREIGN KEY (main_data_id) REFERENCES main_data(id)
);