dongxiejie9387 2013-11-17 10:14 采纳率: 100%
浏览 19
已采纳

Mysql错误重复结果

I wrote a mysql query and got same result twice. Now i can't fix the problem. can anyone please help me.

SELECT first_name , second_name
FROM profile_doctors_main , category
WHERE (first_name LIKE "%'.(string)$name.'%" OR second_name LIKE "%'.$name.'%")
    AND category_name LIKE "%'.$category.'%" AND city LIKE "%'.$city.'%"

result = Sharon Zing

Any helps would be appreciated.

  • 写回答

2条回答 默认 最新

  • dongqia0240 2013-11-17 10:23
    关注

    when you need to query data from multi tables, you should you use phrase 'JOIN', and alias the table when necessary.

    and when you use "JOIN", you should add the "ON" condition, which do something like "where" as a filter that remove the duplicate results.

    Try the sql following(as I do not know about the table field, it's just a sample)

    'SELECT first_name , second_name FROM profile_doctors_main , category 
     on profile_doctors_main.xxx = category.xxx 
     WHERE (profile_doctors_main.first_name LIKE "%'.(string)$name.'%" 
     OR profile_doctors_main.second_name LIKE "%'.$name.'%") 
     AND category.category_name LIKE "%'.$category.'%" 
     AND profile_doctors_main.city LIKE "%'.$city.'%"'
    

    there's another problem, that wrong match of the "and" condition and the "or" condition .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)