MYSQL Tutorial

MySQL NOT RLIKE operator

NOT RLIKE operator

MySQL NOT RLIKE operator checks whether a pattern is not present within an expression. The pattern is supplied as an argument.




Name Description
pat A pattern of string.

MySQL Version: 5.6

Video Presentation

Example: MySQL NOT RLIKE operator

The following MySQL statement will find the author’s name not beginning with ‘w’ and country not beginning with 'U'. The ‘^’ have been used to match the beginning of the name.


SELECT * FROM author 
WHERE aut_name NOT RLIKE '^w' 
AND country NOT RLIKE '^U';

Sample table: author

Sample Output:

mysql> SELECT * FROM author 
    -> WHERE aut_name NOT RLIKE '^w' 
    -> AND country NOT RLIKE '^U';
| aut_id | aut_name             | country   | home_city      |
| AUT004 | S.B.Swaminathan      | India     | Bangalore      | 
| AUT005 | Thomas Morgan        | Germany   | Arnsberg       | 
| AUT009 | Marquis de Ellis     | Brazil    | Rio De Janerio | 
| AUT011 | John Betjeman Hunter | Australia | Sydney         | 
| AUT012 | Evan Hayek           | Canada    | Vancouver      | 
| AUT013 | E. Howard            | Australia | Adelaide       | 
6 rows in set (0.00 sec)

PHP script

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example-not-rlike-function - php mysql examples | w3resource</title>
<meta name="description" content="example-not-rlike-function - php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>A list of Authors with their id, name country and home city. The list set against a condition, and that is, Author's name should not begin with 'w' and also not with 'U':</h2>
<table class='table table-bordered'>
<th>Author's id</th><th>Author's name</th><th>Country</th><th>Home city</th>
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT *
FROM author
WHERE aut_name NOT RLIKE "^w"
AND country NOT RLIKE "^U"') as $row) {
echo "<tr>";
echo "<td>" . $row['aut_id'] . "</td>";
echo "<td>" . $row['aut_name'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['home_city'] . "</td>";
echo "</tr>";

View the example in browser

All String Functions

MySQL String Functions, slide presentation

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.