SQL: How to perform string does not equal

前端 未结 6 386
长发绾君心
长发绾君心 2020-12-22 20:34

I have the following query

SELECT * FROM table
WHERE tester <> \'username\';

I am expecting this to return all the results where test

相关标签:
6条回答
  • 2020-12-22 20:50

    Try the following query

    select * from table
    where NOT (tester = 'username')
    
    0 讨论(0)
  • 2020-12-22 20:54

    NULL-safe condition would looks like:

    select * from table
    where NOT (tester <=> 'username')
    
    0 讨论(0)
  • 2020-12-22 20:54

    The strcomp function may be appropriate here (returns 0 when strings are identical):

     SELECT * from table WHERE Strcmp(user, testername) <> 0;
    
    0 讨论(0)
  • 2020-12-22 21:00

    Another way of getting the results

    SELECT * from table WHERE SUBSTRING(tester, 1, 8)  <> 'username' or tester is null
    
    0 讨论(0)
  • 2020-12-22 21:14

    Your where clause will return all rows where tester does not match username AND where tester is not null.

    If you want to include NULLs, try:

    where tester <> 'username' or tester is null
    

    If you are looking for strings that do not contain the word "username" as a substring, then like can be used:

    where tester not like '%username%'
    
    0 讨论(0)
  • 2020-12-22 21:15
    select * from table
    where tester NOT LIKE '%username%';
    
    0 讨论(0)
提交回复
热议问题