2016-09-25 05:58
浏览 760


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

图片转代码服务由CSDN问答提供 功能建议

在我的 MySQL 中我有 user_role_id

我想从表 tbl 中选择所有,其中 user_role_id 不等于 1,4 到目前为止,我只使用单一不等于

  select * from tbl where user_role_id!= 4  

请帮助我解决倍数不等 的语法

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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);


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

    "SELECT * FROM tbl WHERE user_role_id NOT IN (1, 4, 5)"
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题