Search with comma-separated value mysql(用逗号分隔值 mysql 搜索)
问题描述
我有 2 个表 customers 和 imap_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 个字段 from 和 to 和 to 字段包含逗号分隔值.
the imap_emails table has 2 fields from and to and to field contains comma separated values.
我需要从第一个表中获取电子邮件,然后在 imap_emails 上搜索 to 和 from.
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的join示例
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 搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用逗号分隔值 mysql 搜索
基础教程推荐
- Web 服务器如何处理请求? 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
