douzhuanfen5923 2018-06-05 10:36
浏览 77
已采纳

如何在MySQL查询的结果中找出特定列的值?

I have a table with the following columns: id, firstname, lastname, category. And let's say i have data with categories like: action, comedy, drama, horror. My query is

SELECT * FROM tablename WHERE firstname LIKE '%John%'

The query will bring all the records that contain 'John' in firstname, and let's assume that the records have different values for categoty: action and comedy only.

How to find out the list with all the values available in category column for this specific search.

Thanks!

  • 写回答

4条回答 默认 最新

  • dongluan2612 2018-06-05 10:43
    关注

    If you want a distinct list of categories, where firstname is like John:

    SELECT DISTINCT category FROM tablename WHERE firstname LIKE '%John%'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突
  • ¥15 如何在线硕士了解,广告太多,希望有真实接触过的人回答下?(标签-学习|关键词-在线硕士)
  • ¥15 zabbix6.4与frp如何进行联动