用逗号分隔值搜索mysql

用逗号分隔值搜索mysql

本文介绍了用逗号分隔值搜索mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个表 customersimap_emails.customer 表包含客户的电子邮件.

我正在使用 PHP-IMAP 从电子邮件服务器获取电子邮件,然后保存到数据库表 imap_emails.

imap_emails 表有 2 个字段 fromtoto 字段包含逗号分隔值.>

我需要从第一个表中获取电子邮件,然后在 imap_emails 上搜索 tofrom.

首先我想到了一个 LIKE 条件来搜索,但我想要像 FIND_IN_SET 或其他东西.

我怎样才能以更好的方式实现这一目标?(由于某些原因我不能在这张表上使用关系)

请指教.

解决方案

基于 FIND_IN_SET 进行连接的示例

SELECT *从 imap_emails内部连接客户ON FIND_IN_SET(customers.email, imap_emails.to) >0

您没有说明您想如何缩小范围(即,如果一封电子邮件使用了 2 个电子邮件地址,您是否希望将两封电子邮件都带回来),因此在此阶段无法添加太多内容.

i have 2 tables customers and imap_emails. customer table contain emails of customers.

I am using PHP-IMAP to fetch email from email server and then saving to database table imap_emails.

the imap_emails table has 2 fields from and to and to field contains comma separated values.

i need to fetch emails from first table and then search against to and from on imap_emails.

First i thought about a LIKE condition to search , but i would like to have something like FIND_IN_SET or something other.

How can i achieve this in a better way ? ( For some reasons i cannot use relations on this table )

Please advice.

解决方案

Example of doing a join based on FIND_IN_SET

SELECT *
FROM imap_emails
INNER JOIN customers
ON FIND_IN_SET(customers.email, imap_emails.to) > 0

You don't say how you want to narrow this down (ie, if an email uses 2 email addresses do you want both emails brought back), so can't add much at this stage.

这篇关于用逗号分隔值搜索mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 21:57