dsg24156 2017-01-14 13:27
浏览 55
已采纳

带有术语研究的SQL请求

I'm currently working on a search bar which return every Car Brand and Car Model combined according to what the user write into a textbox (Autocomplete function of jQuery)

I tried different things but, doesn't find what I need.

Here's my request (Not working) :

SELECT carBrand_lib, carModel_lib FROM Model AS mo 
INNER JOIN Brand AS br ON br.carBrand_ID = mo.carBrand_ID 
GROUP BY carBrand_lib, carModel_lib 
HAVING (carBrand_lib + carModel_lib) 
LIKE '%".$searchTerm."%' 
ORDER BY carModel_lib ASC LIMIT 10

I did another request which working, but only with the Car Brand or the Model separated but don't find for the two combined.

SELECT carBrand_lib, carModel_lib FROM Model AS mo 
INNER JOIN Brand AS br ON br.carBrand_ID = mo.carBrand_ID 
WHERE carModel_lib LIKE '%".$searchTerm."%' OR carBrand_lib 
LIKE '%".$searchTerm."%' 
ORDER BY carModel_lib ASC LIMIT 10

An example of what I need :

If the user search "Porsche 9" for example, it will return from the database : "Porsche 911" or something else containing "Porsche 9", in a list.

With "GT" as research, the database will return "Ford GT", "Nissan GTR"...


How can I make my SQL request to research in two columns combined at the same time ?

  • 写回答

1条回答 默认 最新

  • duanlai1855 2017-01-14 14:45
    关注

    Problem Solved ! I simply used the "CONCAT()" function.

    SELECT carBrand_lib, carModel_lib FROM Model AS mo 
    INNER JOIN Brand AS br ON br.carBrand_ID = mo.carBrand_ID 
    WHERE CONCAT(carBrand_lib, ' ', carModel_lib ) 
    LIKE '%".$searchTerm."%' 
    ORDER BY carModel_lib ASC LIMIT 10
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 idea自动补全键位冲突
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页