mysql - Using NOT LIKE in WHERE Clause -


the user table below,

name  | username    | email  ---------------------------------   joe  |    joe      | joe@mail.com       ---------------------------------   john |    abc\john | john@abc.com       ---------------------------------   kate |    kate     | kate@mail.com  ---------------------------------   ron  |    abc\ron  | ron@abc.com   --------------------------------- 

the mysql query select fields table username in table doesn't start "abc\". since user logs in application using active directory credentials, user name stored in domain\username (eg: abc\username). tried create query not working.

select * user username not 'abc\\\\%_' 

but not working.it pulling user records.

name  | username    | email  ---------------------------------   joe  |    joe      | joe@mail.com       ---------------------------------   john |    abc\john | john@abc.com       ---------------------------------   kate |    kate     | kate@mail.com  ---------------------------------   ron  |    abc\ron  | ron@abc.com   --------------------------------- 

but need users username doesn't starts "abc\".

name  | username    | email  ---------------------------------   john |    abc\john | john@abc.com       ---------------------------------   ron  |    abc\ron  | ron@abc.com   --------------------------------- 

i tried filter respect email address below working fine

select * user email not '_%@abc.com'  

i new queries , can manage write simple queries 1 not sure if following correct way.

your query works fine me. think problem using backslash in string query.

            $not_like= "abc\\%";             $statement = $db->prepare("select * `user` `email` not ?");             $statement->bind_param('s', $not_like);             $statement->execute();             $result = $statement->get_result();             while($get_users = $result->fetch_assoc()) {                 echo($get_users['username']);             }             $result2->free(); 

Comments