Limit Rows with the WHERE clause — MySQL Beginner Series
This blog post is an excerpt from premium MySQL Beginner content I am creating to help anyone learn how to use MySQL. Thank you for reading and please do provide feedback.
✔️ You may also be interested in the blog post, MySQL Beginners Series — The SELECT statement, which is a primer for this article.
Limit Rows with the WHERE clause
So far, we have been executing SELECT *
and SELECT
column_list types of queries. Not only are we retrieving all of the columns, but, also every row in the FROM
clause table is returned. Oftentimes, it is not ideal to retrieve all of a tables’ rows since we may need a more specific set of them.
To filter the returned number of rows from a SELECT
query, we use the WHERE
clause with one or more search filter conditional tests, constraining the number of rows returned by the FROM
clause table.
Comparison Operators
These conditional tests are applied to every row in the FROM
clause table against column string, number, or date value data using any one or more of these basic comparisons operators:
=
: Equals to<>
or!=
: Not equals to<
: Less than>
: Greater than<=
: Less than or equals to>=
: Greater than or equals to
(Additional conditional tests are possible using more advanced filtering mechanisms such as: LIKE
, IN()
, and BETWEEN
. However, their discussion is beyond the scope of this introductory article.)
Each conditional test returns one of the following values:
TRUE
FALSE
- Unknown
For a row to be included in the result set, its specific conditional test (for however many columns are targeted) must evaluate to TRUE
.
Stay tuned — more to come
More articles covering MySQL topics are still to come here on the Digital Owl’s Prose blog. Keep up with all of the premium MySQL Beginner content as I write and release them, along with a weekly MySQL email tip, by exploring the sign-up option below.
Do you need to learn MySQL? Just starting and confused about how to query a table and get the data you need? I am creating premium MySQL Beginners content for this specific reason. To help those who want to learn the basics of MySQL but don’t know where to start. Learn more about the premium blog posts as I develop and release them.
Like what you have read? See anything incorrect? Please comment below and thank you for reading!!!
A Call To Action!
Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.
Visit the Portfolio-Projects page to see blog posts/technical writing I have completed for clients.
Support my work with a coffee!
To receive email notifications (Never Spam) from this blog (“Digital Owl’s Prose”) for the latest blog posts as they are published, please subscribe (of your own volition) by clicking the ‘Click To Subscribe!’ button in the sidebar on the homepage! (Feel free at any time to review the Digital Owl’s Prose Privacy Policy Page for any questions you may have about: email updates, opt-in, opt-out, contact forms, etc…)
Be sure and visit the “Best Of” page for a collection of my best blog posts.
Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.
Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, are performed on a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.
Check out this review on one of my favorite SQL books; Book Recommendation — SQL Antipatterns
How can I help you?
- Are you thinking of starting up a blog? I use WordPress for my blog. Let’s both save money on the plans offered. 💸
- Grab a Gmail HTML Email Signature template from my Etsy shop and make your emails pop and stand out. ✉️
- Need hosting for your next web application or WordPress site? I use and highly recommend Hostinger. They have great pricing and service.
- I enjoy reading Refind: The essence of the web, every morning in your inbox. Subscribe for free. Help me get a premium subscription by signing up yourself with my referral link.
- Grab a free pack of mobile Creator wallpapers.
- Just getting started or wanting to learn MySQL? Find out about my premium blog posts and MySQL Beginner Series here.
Disclosure: Some of the services and products links in this post are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.
Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.
Originally published at https://joshuaotwell.com on March 23, 2022.