Ready to Level Up Your Industrial Automation Skills?

Learn in-demand skills with 100+ expert-led courses, earn certifications, and advance your career.

Try RealPars FREE for 7 Days
Thank you! Check your email for confirmation.

What are SQL Where and Like Statements Basics? (PART 3 of 8)

In this article, you will learn about relational databases and about the language of SQL.
Listen to this article

If you are just now joining along with this series of articles, please note that you are going to learn about SQL programming basics.

If you would like to follow along with us, please review the RealPars article, How to install MySQL and import a sample database, on how to download and setup MySQL database on your computer.

What are SQL Where and Like statements basics continues where we left off within the What are SQL programming basics article for our series of lessons covering SQL programming.

In this article, you will learn more about relational databases and about the language of SQL.

In subsequent lessons we will apply what we have learned in these articles, to view a sample database and program a few SQL queries to read and write to the database that will provide specific organized data.

With this Entity Relationship Diagram or ERD, we can see how the tables are related to one another in the RealPars model database.

We continue here from the previous SQL article, What are SQL programming basics, with using the Select statement, using some additional clauses.

First, we need to get familiar with Where and Like clauses.

Where and Like Clauses

SQL Where Clauses

Look at this SQL programming example.

The Where clause is optional and specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword Where.

Where Conditional Selections

Conditional selections used in the Where clause are:

SQL Like Clause

The LIKE clause is a very powerful operator that allows you to select only rows that are like what you specify.

Percent Sign

The percent sign can be used as a wild card to match any possible character that might appear before or after the characters specified.

Where and Like Programming Examples

Programming Example – LIKE ‘J%’

This is the Students table that resides in our database.

Start writing the SQL statement in the SQL Query Tab to find any first names that start with the letter J.

Note that the strings must be in single quotes.

Now, run the statement by pressing the Execute Query button to view the results in the Output Panel.

The results display only first names beginning with the letter J.

LIKE ‘%N’ (Programming Example)

Specify another SQL statement to find the students’ first names that ends in the letter N.

Change the LIKE operator to compare names ending in the letter N.

Then press the Execute Query button to run the statement and view the results in the Output Panel.

The results display only first names ending with the letter N.

Firstname = ‘Jean’ (Programming Example)

Another example using the SELECT statement could be to select records with a specific first name.

Once again, use MySQL Workbench to write the new statement, looking for only records with the first name Jean.

This query would then only select rows where the first name equals Jean exactly.

To run the statement, Press the Execute Query button.

Then, view the result in the Output Panel, which displays only records with the first name Jean.

StudentNumber < 120 (Programming Example)

Let’s write another SQL statement in MySQL Workbench to identify students with student numbers less than 120.

Press the Execute Query button to run the statement and view the results in the Output Panel.

The results display only records with the student numbers less than 120.

LIKE ‘%U%’ (Programming Example)

Now a department asks us to write a statement to select only students’ last names containing the letter U.

To create this query, use the wildcard character, percent sign, before and after the letter U.

Once again, press the Execute Query button to run the statement and view the results in the Output Panel.

The results display only the Last Name, First Name and Credit Limit columns and records with last names that include the letter U.

This concludes the article on the basics of SQL Where statements and SQL Like statements. By now you should be getting accustomed to simple SQL statements and ready for the next lesson in SQL.

Next SQL Lessons

Our series of subsequent articles to follow will consist of the following lessons.

Be sure to read these articles offering prerequisite learning for the beginner and then unto the more advanced statements of SQL learning.

The next SQL lessons soon to be available are:

– Order By Clause and Expression statement language elements

– Inner Join, And/or, Having and Between Clause statement language elements

– Subquery, Exists and Create Table Clause statement language elements

– Join and Union Clause statement language elements

– Cross Join and Inner Join Clause statement language elements

If you would like to get additional training on a similar subject please let us know in the comment section.

Check back with us soon for more automation control topics.

Got a friend, client, or colleague who could use some of this information? Please share this article.

The RealPars Team

How to Install MySQL and Import a Sample Database (Part 1 of 8)

What are SQL Programming Basics? (Part 2 of 8)

▶ What are SQL Where and Like Statements Basics? (Part 3 of 8)

What are the SQL Order by Clause and Expression Statement Language Elements? (Part 4 of 8)

What are the SQL Inner Join, And/or, Having and Between Clause Statement Language Elements? (Part 5 of 8)

What are the SQL Subquery and Exists Clause statement language elements? (Part 6 of 8)

What is the SQL Create Table Clause Statement Language Element? (Part 7 of 8)

What are the SQL Cross Join, Inner Join, and Union Clause statement language elements? (Part 8 of 8)

Join the Top 1% of Automation Engineers

Start Your 7-day Free Trial

Learn from Industry Experts

Start your learning journey today!
With a 7-day trial, then 25/month
Start Learning For Free