drlndkhib08556095 2018-02-04 23:32
浏览 87

MySQL - 如果查询中的任何单词匹配,则在多列中使用REGEX选择一行

I have three tables:

  1. post
  2. tags
  3. past_tags

So, I want to make a simple search to get the post ID using it's title only, related tags only, and title and tag.

To explain my point take this example:

In post table I have columns named (post_id, post_title)

Example: post_id: 1 - post_title: my new super car

In tags table I have columns named (tag_id, tag_name)

Example: tag_id: 5 - tag_name: red

In post_tags I record the post_id of "post" and the tag_id of "tag":

Example: post_id: 1 - tag_id: 5

so each post can has many tags (a simple relationship).

I want to select the post post_id if I enter any of these queries:

  1. supper car
  2. red car
  3. red super car
  4. super red car
  5. red

It's a kind of merging the results and match the post_id even if the query is not related to one column.

Thank you.

  • 写回答

1条回答 默认 最新

  • douyue5856 2018-02-11 23:11
    关注

    For "word" matching, learn about FULLTEXT indexing. REGEXP is less practical.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题