douyi2664 2013-07-10 09:00
浏览 19
已采纳

搜索多个表格中的前三个字母

movie_table

id  movie_name      genre   rating
1   Green lantern   action  7.5
2   Seven           horror  8.5
4   django          comedy  6.0

tv_serial

id  serial_name     genre   rating
1   game of throne  action  9.5
2   walking dead    horror  8.5
4   breaking bad    comedy  6.0

Now if I put any name starting with G in the search bar the list must show green lantern and game of throne. Just need the sql query to extract these data thank you.

Edit

To sound more generalized and to be helpful for others, this question is rephrased as: How to implement Trie in php where data is obtained from a mysql table?

  • 写回答

1条回答 默认 最新

  • dsafq2131321 2013-07-10 09:11
    关注

    Try following query :

    SELECT movie_name as Name
    FROM movie_table
    WHERE movie_name like 'G%'
    union all
    SELECT serial_name as Name
    FROM tv_serial
    WHERE serial_name like 'G%'
    

    SQLFIDDLE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么