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.
If you are just now joining along with this series of articles, please note that you are going to learn about SQL programming basics.
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.
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.
By Wally Gastreich
Posted on Jan 6, 2020
By Wally Gastreich
Posted on Jan 6, 2020
In this blog post, you’ll learn about the mindset that helped me getting a PLC programming job with NO experience. This is my personal experience as someone who searched for a job in this field and as an employer who reviews resumes and interviews candidates for a variety of projects. So let’s get started!
At RealPars, we focus on teaching automation engineers, controls engineers, and technicians the skills that they need to be successful in their careers both now and in the future. We are constantly collaborating with manufacturers to understand what the future of...
In this article, you're going to learn how to use Omron Sysmac Studio 3D simulation function for your robatic applications. The 3D function is easily added to Sysmac Studio by way of a license from OMRON. We’ll give you more details on that later.Simulation of a...
RealPars is the world's largest online learning platform for cutting-edge industrial technologies.
+31 10 316 6400
Mon - Fri 8:30 am to 5:30 pm (CET)
Rotterdam Science Tower,
3029AK Rotterdam, The Netherlands
Help & Support
Refund & Cancellation Policy
© 2022 RealPars B.V. All rights reserved.
Created with coffee and tea in Rotterdam.