SQL Query Where Field DOES NOT Contain $x

SQL Query Where Field DOES NOT Contain $x

In SQL, if we want to filter the rows that do not contain the $x as a property, we can use the NOT LIKE operator. In this blog, we will learn how we can filter the rows that do not contain $x as a value.

Table of Contents:

SQL Query Where Field DOES NOT Contain $x

In SQL, if we want to print those rows that do not contain $x as their values, we have to use the NOT LIKE Operator. Let’s have a look at the syntax of the NOT LIKE operator.

Syntax:

SELECT *
FROM your_table
WHERE column_name NOT LIKE '%$x%';

Example of NOT LIKE Operator:

Suppose we have a table Customer, and we have to print the fields that do not contain $x.

CustomerID CustomerName Email
1John Doe[email protected]
2Jane Smith[email protected]
3Sam Green[email protected]
4Alice Brown[email protected]
5Tom Richards[email protected]
6Sarah Leesara$xlee$domain.com

Now let’s print only those rows, that do not contain $x in their email.

Query:

SELECT CustomerID, CustomerName, Email
FROM Customers
WHERE Email NOT LIKE '%$x%';

Output:

CustomerID CustomerName Email
1John Doe[email protected]
2Jane Smith[email protected]
3Sam Green[email protected]
4Alice Brown[email protected]

Explanation: the above query will filter the last two rows that contain $x as their string, and return the rest rows.

Conclusion

So far in this article, we have learned how we can print the roes that do not contain a particular string in it. If you want to excel in your career in SQL, you may refer to our SQL Course.

About the Author

Data Engineer

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.

business intelligence professional