MySQL LIKE 表的通配符
我有一个 PHP 文档,它将执行一些 MySQL 并回显它。
代码:$query1 = "SELECT * FROM feed,recipients WHERE feed.title LIKE \"%recipients.suburb%"\ ORDER BY pubDate DESC";
recipients.suburb (table.column) 位于我的 MySQL 数据库中。我如何对此执行通配符?
这可行,但我不能对桌子这样做?
$query1 = "SELECT * FROM feed,recipients WHERE feed.title LIKE '%test%' ORDER BY pubDate DESC";
我想检查 feed.title
列> 并查看此文本是否位于 recipients.suburb
中。它用于最终向用户发送电子邮件的脚本,该脚本基于与用户位置相关的 MySQL 文本。
I have a PHP document which will execute some MySQL and echoes it back.
Code:$query1 = "SELECT * FROM feed, recipients WHERE feed.title LIKE \"%recipients.suburb%"\ ORDER BY pubDate DESC";
recipients.suburb (table.column) is in my MySQL DB. How can I perform wildcards on this?
This works, but I can't do it for tables?
$query1 = "SELECT * FROM feed, recipients WHERE feed.title LIKE '%test%' ORDER BY pubDate DESC";
I'd like to check the column feed.title
and see if any of this text is in recipients.suburb
. It is for a script that will eventually email users, based on text from MySQL co-relating to the location of the user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
如果您有一个带有 id 的
suburb
表,那么您会得到更好的 ER 设计。然后,您可以在feed
表和recipients
表中拥有外键suburb_id
。这将在您在此处查找的feed
和recipient
之间创建多对多关系。解决方案是使用联接将收件人与郊区相同的提要进行匹配。
这是我的建议:
并使用这个 SELECT 语句:
You would be better off with a better E-R design where you have a
suburb
table with an id. Then you can have foreign keysuburb_id
in both thefeed
table and therecipients
table. This would create a many-to-many relationship betweenfeed
andrecipient
that you are looking for here.The solution would then be to use joins to match recipients to feeds where the suburb is the same.
Here is what I would propose:
And use this SELECT statement: