How to use the SQL LIKE Condition

How to use the SQL LIKE Condition


How to use the SQL LIKE Condition

Learn how to use the SQL LIKE Condition to perform pattern matching in SQL. This tutorial demonstrates how to write a query using the LIKE Condition with an easy to follow example.

SQL LIKE Condition (and sample data):
https://www.techonthenet.com/sql/like

SQL Tutorials:
https://www.techonthenet.com/sql/inde

Don’t forget to subscribe to our channel for more great SQL tutorials!

Visit us at: https://www.techonthenet.com
or follow us on:

Facebook: https://www.facebook.com/techonthenetcom
Twitter: https://twitter.com/tech_on_the_net
Pinterest: https://www.pinterest.com/techonthene


Content

0.02 -> The LIKE condition allows you to perform pattern matching in SQL
5.22 -> The best way to understand the LIKE condition is to look at an example
9.06 -> So let's get started
11.1 -> Here we have a table called customers containing the following data
16.12 -> Let's write a SELECT statement that uses the LIKE condition
19.52 -> to find all customers whose last_name starts with "J"
23.52 -> We'll start our query by entering SELECT * FROM customers
29.32 -> This tells the database to select all columns from the customers table and return a result set
35.72 -> Next, we will enter the WHERE keyword to start our WHERE clause
40.76 -> This is where we will use the LIKE condition
43.64 -> When using the LIKE condition, you can choose from two different wildcards
48.38 -> the percent sign (%) and the underscore sign (_)
51.96 -> The % allows you to match any string of any length including zero length
57.8 -> while the underscore character (_) allows you to match on a single character
63 -> The % is the most commonly used wildcard for the LIKE condition
67.44 -> Since we want to return only those records where the last_name starts with "J"
71.96 -> We use the % wildcard
74.44 -> and enter last_name LIKE "J%" as our LIKE condition
81.7 -> This tells the database that we want to return all records where the last_name starts with "J"
87.22 -> Finally, we will enter an ORDER BY clause to sort our query results
93.02 -> We will enter ORDER BY last_name so that our result set is sorted by last name in ascending order
99.72 -> Now let's run our query and see what results we get
103.88 -> Our query returns two records in the result set
107.7 -> The first record has a customer last name of Jackson
111.42 -> and the second record has a customer last name of Johnson
115.28 -> This covers a simple example of how to use the SQL LIKE condition
120.34 -> If you want to see more examples
122.8 -> or wish to download the sample data we used for this tutorial
125.77 -> please visit our website at TechOnTheNet.com
129.18 -> You can also try the examples in our SQL editor on our website
134.37 -> Look for the "Try It" button next to each example
137.527 -> If you found our tutorial helpful, please leave a like on this video
141.42 -> And don't forget to subscribe to our YouTube channel for more great SQL tutorials

Source: https://www.youtube.com/watch?v=vEt7bDnXlnY