Like Filter in MySQL Queries - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Like Filter in MySQL Queries

Share This


In the where clause section, we have discussed that the conditions can be used in SQL queries. In those cases, we have written the queries where exact matching is being performed for a string using the = symbol. But in many cases, we need to filter data based on partial matching of the string. In case of partial matching, we have to use like a filter.

To test this, let us start with some more records. After truncating the table, we are executing the following SQL queries to prepare the table.

insert into books values ('C Programming Language', 2, '9780131103627', 'Brian W. Kernighan, Dennis M. Ritchie', 'Paperback', 'Prentice Hall', 'April 1988', 67.00);
insert into books values ('Java: A Beginners Guide', 7, '9781259589317', 'Herbert Schildt', 'Paperback', 'McGraw-Hill Education', 'October 2017', 40.00);
insert into books values ('Python Programming', 1, '9781590282755', 'Zelle, John', 'Paperback', 'Franklin, Beedle & Associates', 'April 2014', 70.00);
insert into books values ('Design and Analysis of Algorithm', 1, '9781976735974', 'BHUPENDRA SINGH MANDLOI', 'Paperback', 'Independently published', 'January 2018', 5.00);
insert into books values ('Introduction to Algorithms', 3, '9780262033848', 'Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein', 'Hardcover', 'The MIT Press', 'July 2009', 99.00);
insert into books values ('Operating Systems', 2, '9780985673529', 'Thomas Anderson, Michael Dahlin', 'Paperback', 'Recursive Books', 'August 2014', 72.00);

Like Filter and Select Queries


If we run select * from books; query, the query returns all the tuples of the table. If we want to apply the filter to see the names of all the books that have the word Programming in its name, we can use like in where clause instead of = symbol. The query is shown below:



Where Clause and Update Queries


Similarly, like filter can be used also with an update query. Let us increase the price of the books that contain Programming in its name. The query can be written like this:



Where Clause and Delete Queries


In this context, if you want to delete the books that contain the word Programming in their name, the query can be written like this:





Happy Exploring!

No comments:

Post a Comment