Divi WordPress Theme

Topic: How to perform string does not equal in MySQL  (Read 89 times)

Offline Chris

  • Junior Guru
  • **
  • Posts: 77
  • iTrader: +0/-0
    • View Profile
How to perform string does not equal in MySQL
« on: October 31, 2019, 11:24:00 AM »
I have the following mysql query:

    SELECT * FROM table WHERE name <> ‘username’;

I am expecting to return all the results where name is not the string username, But this not working. Am I doing wrong?

Thanks!
VPS Hosting - AccuWebHosting

Offline Kailash

  • Web Hosting Master
  • *****
  • Administrator
  • Posts: 648
  • iTrader: +153/-0
    • View Profile
Re: How to perform string does not equal in MySQL
« Reply #1 on: October 31, 2019, 11:25:47 AM »
Your “where” clause will return all rows where name does not match username AND where name is not null.

If you want to include NULL results as well, you can try following where clause:

    where name <> ‘username’ or name is null

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

    where name not like ‘%username%’

- Kailash
Shopify Divi WordPress Theme
Tags: