两个关联表字段如下:
product
product_id    product_nameproduct_reviews
review_id    product_id    comment我想要完成的功能:搜索某个关键字,这个关键字like comment和product_name字段,搜出来product_name不能重复

解决方案 »

  1.   

    贴建表及插入记录的SQL,及要求结果出来看看
      

  2.   

    select distinct product_name
    from product A,product_reviews B
    where A.product_id = B.product_id and B.comment like '%关键字%'
      

  3.   


    两个关联表字段如下:
    product(产品表)
    product_id    product_name
    1              name1
    2              name2
    3              name3
    4              name4
    5              name5
    6              name6
    7              name7product_reviews(评论表)
    review_id    product_id    comment
    1               1          comment1
    2               2          comment name 2
    3               1          comnamement3
    4               3          comment4
    5               3          comment5
    6               4          comment6比如我搜索 name,name会去匹配product_name和comment, 条件:1、product在product_reviews要有记录   2、product_name不能重复
    所以搜索出来的结果应该是
    product_id    product_name
    1              name1
    2              name2
    3              name3
    4              name4
      

  4.   


    这样搜索,如果product_reviews没有记录也会搜索出来,我想过滤掉没有评论记录的。