- The Query
- Posts
- 🤓 Speed Up Your SQL Queries
🤓 Speed Up Your SQL Queries
The Query (aka Kyle and Cody) here 👋
Here’s what we have for you today:
A SQL tip to make your queries run faster ⚡️
Remote data jobs and freelance work (you can do it!) 😎💪
Datasets for practicing data visualization 📊
A meme you’ll think about when falling asleep 🤣
select * from data-jobs
remote, data jobs
Because who likes writing SQL from a busy office?
Data Analyst @ Foodbuy — $65-80k per year (apply here)
Data Analyst, Healthcare @ Sentara — $70-105k per year (apply here)
Senior Data Analyst @ Rhino — $115-143k per year (apply here)
freelance gigs
Need work experience? Get real experience with real projects.
Looker Studio Help — $33-65 per hour (apply here)
Data Analyst Needed — contract to hire (apply here)
Social Media Data Analyst — $10-20 per hour (apply here)
def content_spotlight(🔦):
This week, we’re featuring a repository of datasets from Plotly.
Plotly is a data visualization tool you can use with Python. This catalog of datasets features the data behind the scenes of many of their code examples.
These would be great datasets to use to practice your data visualization in Python or any other data viz tool like Power BI, Tableau, or Excel.
If you do an analysis of any of these make sure to share it on Linkedin and tag Cody and Kyle in your post!
class SQLMiniLesson:
Speed Up Your Queries By Joining on This Data Type…
Kyle here 👋 — Here’s a quick SQL tip to help your queries run faster.
There's nothing that bogs down a data analyst like a slow SQL query.
Often, we end up with numbers stored as strings in our data.
Convert them to integers if you can!
One way to improve the performance of your queries is to join tables using integer values instead of strings.
Why does this matter?
It's all about memory usage.
Integers take up less space in memory than strings, leading to faster joins and more efficient processing.
When joining on strings, the database has to compare each character in the string, which can be time-consuming, especially for longer strings or large datasets.
Additionally, string comparisons are often case-sensitive, which can lead to slower performance.
If your database contains numbers stored as strings, you can convert them to integers using the CAST or CONVERT functions, depending on your SQL dialect.
Here's an example using BigQuery's CAST function:
with string_id_table as (
SELECT
CAST(id AS INT64) as id
, other_columns...
FROM table
)
SELECT
columns...
FROM string_id_table s
LEFT JOIN table2 t
on s.id = t.id
Don't let strings slow you down – optimize your queries by using integers whenever possible.
This tip won't fix all your problems, but it should help.
And it’s good to keep things like this in mind to understand how SQL is executing under the hood.
Happy analyzing!
import memes as 😂
Who else lays awake at night thinking about their SQL queries??? 🤣🤓
content & resources 🤓
1. Become a Data Analyst Guide: Our full guide on what it takes to land a job as a data analyst.
2. Download our SQL Cheatsheet as a PDF and desktop wallpaper here.
4. Courses: Our course on showcasing your data portfolio is live!
That’s it for today.
Stay crunchin’ folks and see you next week!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
What'd you think of today's newsletter? |