- The Query
- Posts
- 🤓 12 SQL mistakes data analysts should avoid
🤓 12 SQL mistakes data analysts should avoid
Read Time: 3 minutes
GM crunchers! The Query here — the data newsletter that's like the ultimate Tableau dashboard for your data career, providing an interactive and dynamic view of the data landscape.
Here’s what we have for you today:
12 common SQL mistakes ☺️
A new dataset for portfolio projects 🔥
A more perfect UNION
A heck of a lot of howls 🤪
def learn_data_analysis(👨💻):
1. Introduction to temp tables in SQL Server
A temporary table or “temp table” is exactly what it sounds like — a table that exists temporarily.
If you’re using SQL Server and feel comfortable with the basics (select, from, join, where, etc.), take 10 minutes and read this article on temp tables.
It was a massive unlock for me when I first learned SQL, so I bet it will help you too.
2. 12 common mistakes and missed SQL optimization opportunities
Did you know BETWEEN is inclusive?
The screenshot above is from this article by Haki Benita.
It’s short, sweet, and SUPER helpful for learning some of the nuances of SQL best practices.
select * from dataset-of-the-week
This week’s dataset of the week is Sephora Website data by Raghad Alharbi!
Here’s the schema you’ll be working with:
Some ideas for projects:
What brands and categories are the most popular?
Should Sephora discontinue any of its products/brands?
What recommendations would you make to the R&D department of Sephora in terms of new categories of products that they should research?
class MiniLesson:
UNION vs. UNION ALL
When working with data one common task is appending one table of data to another.
Appending data is kind of like adding more pages to the end of a book or adding more items to the end of a shopping list.
The original data stays the same, but new data is added to the end.
For example, if you have a list of names like this:
Alice
Bob
Charlie
And you append the name "Dave" to the list, the list would then look like this:
Alice
Bob
Charlie
Dave
To append data in SQL we use the UNION command. But there are two ways to do a UNION:
UNION
UNION ALL
An example would look something like this:
While they both serve the purpose of merging query results, there are differences in their behavior and use cases.
UNION: The UNION operation combines the results of two or more SELECT queries and removes any duplicate rows.
Use UNION when you want to merge results from different queries and ensure that the output contains only unique rows, without duplicates.
UNION ALL: The UNION ALL operation combines the results of two or more SELECT queries and retains all rows, including duplicates.
Since UNION ALL does not perform any duplicate elimination, it is generally faster than UNION.
Use UNION ALL when you want to merge results from different queries and keep all the rows, including duplicates, or when you know that there are no duplicates in the result sets and want to improve the query performance.
Now you’ll always know which one to use. Append away!
import memes as 😂
Gotta love Excel 🤣
That’s it for today.
Stay crunchin’ folks and see you next week!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
What'd you think of today's newsletter? |