我有以下查詢SQL:如何執行字符串不等於
SELECT * FROM table
WHERE tester <> 'username';
我期待這個返回所有結果,其中測試儀是不是字符串username
,但這不工作。我想我正在尋找Like
運營商的反面,但我不確定?在我的搜索中,我找到了數字解決方案(這是我從中得到的<>),但這似乎不適用於字符串。
我有以下查詢SQL:如何執行字符串不等於
SELECT * FROM table
WHERE tester <> 'username';
我期待這個返回所有結果,其中測試儀是不是字符串username
,但這不工作。我想我正在尋找Like
運營商的反面,但我不確定?在我的搜索中,我找到了數字解決方案(這是我從中得到的<>),但這似乎不適用於字符串。
你where
子句將返回那裏tester
不匹配username
並在tester
不爲空的所有行。
如果你想包括NULL,請嘗試:
where tester <> 'username' or tester is null
如果您正在尋找不包含單詞「用戶名」作爲子字符串,然後like
可用於:
where tester not like '%username%'
嘗試以下查詢
select * from table
where NOT (tester = 'username')
select * from table
where tester NOT LIKE '%username%';
的strcomp
功能可適當位置(返回0時字符串是相同的):
SELECT * from table WHERE Strcmp(user, testername) <> 0;
NULL安全的條件下會看起來像:
select * from table
where NOT (tester <=> 'username')
您有與'NULL'問題的值值? ('NULL <>'username'' =>'NULL' => false)? – Wrikken 2013-05-01 18:59:42