You are encountering an issue with searching comma-separated values in an IMAP email table. You wish to compare email addresses from a customer table to the "to" and "from" fields in the imap_emails table, which contain multiple email addresses separated by commas.
To achieve this, you could utilize the FIND_IN_SET function. This function allows you to search for a string within a comma-separated list. For instance, the following query will return rows from the imap_emails table where the customer's email address is found in the "to" field:
SELECT * FROM imap_emails INNER JOIN customers ON FIND_IN_SET(customers.email, imap_emails.to) > 0
It is important to note that this query will return all rows where the customer's email address is present in the "to" field, even if there are multiple email addresses listed. If you require more specific conditions, you can modify the query accordingly.
Additionally, you cannot use relationships on the imap_emails table for this operation. However, the provided query offers an alternative approach to searching comma-separated values effectively.
The above is the detailed content of How Can I Efficiently Search Comma-Separated Email Addresses in MySQL?. For more information, please follow other related articles on the PHP Chinese website!