搜索用逗号分隔的mysql [英] Search with comma-separated value mysql

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

问题描述

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

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

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

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

imap_emails表具有2个字段fromto,而to字段包含逗号分隔的值.

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

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

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

首先,我想到了要搜索的LIKE条件,但我想使用类似FIND_IN_SET的东西或其他东西.

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 )

请咨询.

推荐答案

基于FIND_IN_SET进行连接的示例

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

您没有说您要如何缩小范围(即,如果一封电子邮件使用2个电子邮件地址,您是否希望两封电子邮件都被带回),所以在此阶段不能增加太多.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆