- Sloth Bytes
- Posts
- 𦄠5 SQL Tips That will Save Your Life
𦄠5 SQL Tips That will Save Your Life

Hello friends!
Welcome to this weekās Sloth Bytes. I hope you had a great week š

Learn AI in 5 minutes a day
This is the easiest way for a busy person wanting to learn AI in as little time as possible:
Sign up for The Rundown AI newsletter
They send you 5-minute email updates on the latest AI news and how to use it
You learn how to become 2x more productive by leveraging AI

5 SQL Tips That will Save Your Life

(Ok a little dramatic, but Iām a YouTuber.)
I said last week that Iāll do a SQL one š
When I first learned SQL, I thought:
"This is easy. Just SELECT some stuff and vibe."
And it was easy for a while until:
I had to learn how JOINs worked
I started doing more advanced queries where it reached a point it was so unreadable even I couldnāt tell what it did⦠and I wrote it an hour ago
So today Iām dropping a few byte-sized SQL tips that saved my sanity and made me feel like I finally knew what I was doing.
1. Always use LIMIT
while exploring
SELECT * FROM users LIMIT 10;
Why: When you're querying a big table and you're just trying to āsee whatās in there,ā you donāt want to accidentally return millions of rows.
You will crash your tab, your editor, and possibly your will to live.
Use LIMIT 10
(or even 5) while testing.
Bonus tip: Use ORDER BY created_at DESC
in there to see the most recent entries. You'll look like you know what youāre doing.
2. Be explicit with your JOINs
-- š„ Terrifying
SELECT * FROM users, orders;
-- ā
Professional
SELECT * FROM users
JOIN orders ON users.id = orders.user_id;
Why: That first query creates a Cartesian product or if youāre fancy a CROSS JOIN
, meaning every row in users
is combined with every row in orders
. If you have 10,000 users and 20,000 orders... well, thatās 200 million rows. Congrats, you just created a performance nightmare.
Always use ON conditions when joining. Itās a best practice and Your future self will thank you.
3. Use Aliases for Table and Column Names
-- Without aliases
SELECT employees.employee_name, departments.department_name
FROM employees
JOIN departments ON employees.department_id = departments.department_id;
-- With aliases
SELECT emp.employee_name, dept.department_name
FROM employees AS emp
JOIN departments AS dept ON emp.department_id = dept.department_id;
Why: Makes your SQL code more readable and reduce the amount of typing required when working with long tables and column names.
4. Never run DELETE
or UPDATE
without a WHERE
-- šµ Bye-bye data
DELETE FROM users;
-- š Peace of mind
DELETE FROM users WHERE id = 123;
Why: I donāt care how confident you feel. Never EVER delete or update without a WHERE clause.
Pro tip: Run a SELECT first with the same WHERE condition.
If it returns what you expect, then run your DELETE or UPDATE.
SELECT * FROM users WHERE id = 123;
-- Looks good?
DELETE FROM users WHERE id = 123;
5. Select
ONLY What You Need
-- Bad Practice
SELECT * FROM users;
-- ā
Better
SELECT user_id, first_name, last_name FROM users;
Why: SELECT *
is fine when you're exploring but donāt do it for real queries.
Youāll have these issues:
Slower performance (especially on wide tables)
Wasted memory and bandwidth
Accidental exposure of sensitive columns (hello,
user_password
)Fragile queries that break when the schema changes
Be intentional.
Only grab the columns you need . It makes your code faster, clearer, and safer.
Think of it like going to the grocery store:
Do you take everything off the shelf just in case, or do you grab what you actually came for?
Exactly.
If Iām wrong about any of these, please let me know. SQL is not my strongest skillā¦.


Thanks for the feedback as always :)


Open Source Email: Zero
Iām bringing this back. No idea why I stopped. I think I got lazyā¦
What is Zero?
Theyāve also started adding AI features to email:
AI that can answer questions about your inbox
Mass unsubscribe
Auto-labeling
Auto-summarization
The crazy thing is this is still in OPEN BETA. Yeah⦠lots of potential here.
Make sure to reply to their tweet here by saying āThe sloth sent meā
Let's build the future of email together.
ā zero (@zerodotemail)
2:53 AM ⢠Mar 11, 2025


Thanks to everyone who submitted!
jw123450, Kauketz, xanerin, andregarcia0412, bakzkndd, FredericoSRamos, jensmh95, SonnyS10, GaLinux, IveTouchedGrass, ariatheyroyal, E-Sieben, RelyingEarth87, and cre-w (happy late birthday btw! š)
No Yelling
Create a function that transforms sentences ending with multiple question marks ?
or exclamation marks !
into a sentence only ending with one without changing punctuation in the middle of the sentences.
Examples
noYelling("What went wrong?????????")
output = "What went wrong?"
noYelling("Oh my goodness!!!")
output = "Oh my goodness!"
noYelling("I just!!! can!!! not!!! believe!!! it!!!")
output = "I just!!! can!!! not!!! believe!!! it!"
# Only change repeating punctuation at the end of the sentence.
noYelling("Oh my goodness!")
output = "Oh my goodness!"
# Do not change sentences where there exists only one or zero exclamation marks/question marks.
Notes
Only change ending punctuation - keep the exclamation marks or question marks in the middle of the sentence the same (see third example).
Don't worry about mixed punctuation (no cases that end in something like
?!??!
).Keep sentences that do not have question/exclamation marks the same.
How To Submit Answers
Reply with
A link to your solution (github, twitter, personal blog, portfolio, replit, etc)
or if youāre on the web version leave a comment!
If you want to be mentioned here, Iād prefer if you sent a GitHub link or Replit!

New video coming out soon!
I think this one will be about programming mistakes every beginner makes.
Thatās all from me!
Have a great week, be safe, make good choices, and have fun coding.
If I made a mistake or you have any questions, feel free to comment below or reply to the email!
See you all next week.
What'd you think of today's email? |
Want to advertise in Sloth Bytes?
If your company is interested in reaching an audience of developers and programming enthusiasts, you may want to advertise with us here.
Reply