dongyi8795 2016-09-25 05:58
浏览 790
已采纳

选择具有多个不等于where子句的语句

In my MySQL i have user_role_id column

I want to select all from the table tbl where user_role_id is not equal to 1, 4 and 5

Till now i use only for single not equal like

select * from tbl where user_role_id != 4

Kindly help me with the syntax for multiple not equal

  • 写回答

1条回答 默认 最新

  • dongliehuan3925 2016-09-25 06:03
    关注

    You can use the NOT IN Constraint for that which is available in the MYSQL.

    NOT IN() function:

    MySQL NOT IN() makes sure that the expression proceeded does not have any of the values present in the arguments

    Example: If you want to fetch the rows from the table book_mast which contain such books, not written in English and the price of the books are not 100 or 200, the following statement can be used.

    SELECT book_name,dt_of_pub,pub_lang,no_page,book_price  
    FROM book_mast        
    WHERE pub_lang!="English"     
    AND book_price NOT IN (100,200);
    

    Reference: https://www.techonthenet.com/mysql/not.php

    As per your code you need to change the query like.

    "SELECT * FROM tbl WHERE user_role_id NOT IN (1, 4, 5)"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP