avatarNaina Chaturvedi

Summary

The provided content outlines Day 3 of the "15 Days of Advanced SQL Series," focusing on essential SQL commands, joins, and filters, with additional resources for system design, data science, and machine learning projects.

Abstract

Day 3 of the "15 Days of Advanced SQL Series" delves into critical SQL concepts, offering a comprehensive list of important SQL commands such as CREATE, SELECT, JOIN, and WHERE. It explains the syntax and provides examples for implementing these commands. The content also covers the concept of joins in SQL, including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, and CROSS JOIN, with practical illustrations. Furthermore, it discusses data filtering techniques using WHERE clauses and LIKE operator for pattern matching. The article not only serves as a tutorial for SQL learners but also links to a GitHub repository with code examples and projects. Beyond SQL, it compiles a list of system design base concepts and other educational series on topics like data structures, algorithms, and machine learning. The author encourages engagement through comments and subscriptions and promotes a newsletter for tech interviews and coding exercises.

Opinions

  • The author emphasizes the importance of understanding advanced SQL concepts for proficiency in data manipulation and retrieval.
  • There is a clear preference for hands-on learning, as evidenced by the inclusion of implementation examples and GitHub repositories.
  • The author values community engagement and continuous learning, as shown by the invitation for readers to comment, subscribe, and join a tech newsletter.
  • The content reflects a didactic approach, aiming to simplify complex system design concepts for readers.
  • The author believes in the practical application of knowledge, encouraging readers to build projects and participate in coding exercises.
  • There is an opinion that a combination of theoretical knowledge and practical implementation leads to a comprehensive understanding of SQL and system design.

Day 3 of 15 Days of Advanced SQL Series

Pic credits : Segue

Welcome back peeps. Hope all’s well. Last two weeks have been crazy busy at work for me (plus I was traveling).

Day 1 : SQL Basics and Kick start of Advanced SQL Series

Day 2 : SQL Basics, Query Structure, Built In functions Conditions

Day 3 : Most Important Commands, Joins and Filters

Day 4 : Set Theory Operations, Stored Procedures and CASE statements in SQL

Day 5 : Wildcards, Aggregation and Sequences in SQL

Day 6 : Subqueries, Group by, order by and Having clauses in SQL and Analytical Functions

Day 7 : Window Functions, Grouping Sets and Constraints in SQL

Day 8 : BigQuery Basics, SELECT, FROM, WHERE and Date and Extract in BigQuery

Day 9 : Common Expression Table, UNNEST Clause, SQL vs NoSQL Databases

Day 10 : Triggers, Pivot and Cursors in SQL

Day 11 : Views, Indexes and Auto Increment in SQL

Day 12 : Query optimizations, Performance tuning in SQL

Day 13 : Introduction to MySQL, PostgreSQL and Mongo DB, Comparison between MySQL and PostgreSQL and Mongo DB, Introduction to SQL and NoSQL Databases

Day 14 : MySQL in Depth

Day 15 : PostgreSQL inDepth

Anyways, For Day 3 of 15 days of Advanced SQL, we will cover —

Most Important Commands — Part 2

Joins

Filters

Github for Advanced SQL that you can follow —

Projects Videos —

All the projects, data structures, SQL, algorithms, system design, Data Science and ML , Data Analytics, Data Engineering, , Implemented Data Science and ML projects, Implemented Data Engineering Projects, Implemented Deep Learning Projects, Implemented Machine Learning Ops Projects, Implemented Time Series Analysis and Forecasting Projects, Implemented Applied Machine Learning Projects, Implemented Tensorflow and Keras Projects, Implemented PyTorch Projects, Implemented Scikit Learn Projects, Implemented Big Data Projects, Implemented Cloud Machine Learning Projects, Implemented Neural Networks Projects, Implemented OpenCV Projects,Complete ML Research Papers Summarized, Implemented Data Analytics projects, Implemented Data Visualization Projects, Implemented Data Mining Projects, Implemented Natural Leaning Processing Projects, MLOps and Deep Learning, Applied Machine Learning with Projects Series, PyTorch with Projects Series, Tensorflow and Keras with Projects Series, Scikit Learn Series with Projects, Time Series Analysis and Forecasting with Projects Series, ML System Design Case Studies Series videos will be published on our youtube channel ( just launched).

Subscribe today!

System Design Case Studies — In Depth

Design Instagram

Design Messenger App

Design Twitter

Design URL Shortener

Design Dropbox

Design Youtube

Design API Rate Limiter

Design Web Crawler

Design Facebook’s Newsfeed

Design Yelp

Design Uber

Design Tinder

Design Tiktok

Design Whatsapp

Most Popular System Design Questions

Mega Compilation : Solved System Design Case studies

Complete Data Structures and Algorithm Series

Complexity Analysis

Backtracking

Sliding Window

Greedy Technique

Two pointer Technique

Arrays

Linked List

Strings

Stack

Queues

Hash Table/Hashing

Binary Search

1- D Dynamic Programming

Divide and Conquer Technique

Recursion

Github —

Let’s get started with Day 3 .

First we will start with most important and useful commands that you should know and their syntax can be found here.

  • CREATE — To create table or view or database
  • SELECT — To select the data values from the table in a database
  • FROM — To specify table name from where we are retrieving the records
  • WHERE — To filter the results based on the condition specified in the where clause
  • LIMIT — To limit the number of rows returned as the result
  • DROP — To delete the table or database
  • UPDATE — To update the data in the table
  • DELETE — To delete the rows in the table
  • ALTER TABLE — To add or remove columns from the table
  • AS — To rename column with an alias name
  • JOIN — To combine the rows of 2 or more tables
  • AND — To combine rows in which records from both/more table are evaluated using And condition
  • OR — To combine rows in which records from both/more table are evaluated using Or condition
  • IN — To specify multiple values using the where clause/condition
  • LIKE — To search/identify the patterns in the column
  • IS NULL — To check and return those rows that contains NULL values
  • CASE — To return values after evaluating the specified condition
  • GROUP BY — To group rows which consist of same values into the summary rows/columns
  • ORDER BY — To specify the order of the result returned ( ASC or DESC)
  • HAVING — To specify conditions for aggregate functions
  • COUNT — To count the number of rows
  • SUM — To return sum of the column
  • AVG — To return average of the column
  • MIN — To return min value in the column
  • MAX — To return max value in the column

Implementation —

-- CREATE: Create table or view or database
CREATE TABLE employees (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  age INT,
  department VARCHAR(100)
);

-- SELECT: Select data from a table
SELECT * FROM employees;

-- FROM: Specify table name
SELECT * FROM employees WHERE department = 'HR';

-- WHERE: Filter results based on conditions
SELECT * FROM employees WHERE age > 30;

-- LIMIT: Limit the number of rows returned
SELECT * FROM employees LIMIT 10;

-- DROP: Delete table or database
DROP TABLE employees;

-- UPDATE: Update data in a table
UPDATE employees SET age = 35 WHERE name = 'John';

-- DELETE: Delete rows in a table
DELETE FROM employees WHERE department = 'Finance';

-- ALTER TABLE: Add or remove columns from a table
ALTER TABLE employees ADD COLUMN salary DECIMAL(10,2);

-- AS: Rename column with an alias name
SELECT name AS full_name, age AS employee_age FROM employees;

-- JOIN: Combine rows of multiple tables
SELECT employees.name, departments.department_name
FROM employees
JOIN departments ON employees.department_id = departments.department_id;

-- AND: Combine rows using AND condition
SELECT * FROM employees WHERE age > 30 AND department = 'IT';

-- OR: Combine rows using OR condition
SELECT * FROM employees WHERE age > 30 OR department = 'HR';

-- IN: Specify multiple values using WHERE clause
SELECT * FROM employees WHERE department IN ('IT', 'Finance');

-- LIKE: Search patterns in a column
SELECT * FROM employees WHERE name LIKE '%son%';

-- IS NULL: Check for NULL values
SELECT * FROM employees WHERE department IS NULL;

-- CASE: Return values based on conditions
SELECT name, age,
  CASE
    WHEN age > 30 THEN 'Senior'
    ELSE 'Junior'
  END AS employee_level
FROM employees;

-- GROUP BY: Group rows based on common values
SELECT department, COUNT(*) as employee_count
FROM employees
GROUP BY department;

-- ORDER BY: Specify the order of the result
SELECT * FROM employees ORDER BY name ASC;

-- HAVING: Specify conditions for aggregate functions
SELECT department, COUNT(*) as employee_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;

-- COUNT: Count the number of rows
SELECT COUNT(*) FROM employees;

-- SUM: Return sum of a column
SELECT SUM(salary) FROM employees;

-- AVG: Return average of a column
SELECT AVG(salary) FROM employees;

-- MIN: Return minimum value in a column
SELECT MIN(age) FROM employees;

-- MAX: Return maximum value in a column
SELECT MAX(age) FROM employees;

Snippet —

JOINS

Before we start with joins, one must understand the points explained below—

Primary Keys : These are fields/keys in a table which uniquely identifies each record. These are used to join tables.

Foreign Keys : These are fields/keys in a table which the references the primary key of the other table.

Relationships : Relations between the tables can be one to one, one to many and many to many. In one to one relationships, a record in one table is uniquely related to exactly one record in the other table. On the other side, One to many relationships, a record in one table can be related to one or more records in the other table. Lastly, in many to many one or more records in one table are related to one or more records in the other table.

What is a Join?

In SQL, a join operation combines rows from two or more tables based on a related column between them. The purpose of a join is to retrieve data from multiple tables as if they were a single table.

The most common type of join is the INNER JOIN, which is also the default type of join if no specific type is specified.

The join is performed by using the JOIN keyword, followed by the name of the table to be joined and the ON keyword, followed by the condition that relates the tables.

A join is nothing but a construct used to combine rows from two or more tables based on a related/common column between them. It matches the related columns values in two or more tables.

Pic credits : Alphacode

INNER JOIN: Select records that have matching values in both tables.

LEFT JOIN: Select records from the first (left-most) table with matching right table records.

RIGHT JOIN: Select records from the second (right-most) table with matching left table records.

CROSS JOIN : Select records in the first table multiplied by the records in the second table.

FULL JOIN: Selects all records that match either left or right table records.

Format —

SELECT column_names

FROM table1 JOIN table2

ON column_name1 = column_name2

WHERE condition

Format —

Inner Join
SELECT column_names
FROM table1 INNER JOIN table2
ON column_name1 = column_name2
WHERE condition
-------------------------------
Left Join
SELECT column_names
FROM table1 Left JOIN table2
ON column_name1 = column_name2
WHERE condition
-----------------
Right Join
SELECT column_names
FROM table1 Right JOIN table2
ON column_name1 = column_name2
WHERE condition
-------------
Full Join
SELECT column_names
FROM table1 FULL OUTER JOIN table2
ON column_name1 = column_name2
WHERE condition
-------------
Cross Join
SELECT column_names
FROM table1 CROSS JOIN table2

Snippet —

Filtering the Data

In SQL, the WHERE clause is used to filter the data retrieved by a query. The WHERE clause is added to a SELECT, UPDATE, or DELETE statement and specifies the conditions that must be met for a row to be included in the result set or to be updated or deleted.

For filtering, two types of operators are used —

  1. Comparison Operators : < , >, !=, ==
  2. Text Operators, LIKE

WHERE is used to filter the rows that meet certain condition or criteria.

LIKE operator % is used to filter/replace any number of characters.

Multiple conditions can be specified in the WHERE clause using logical operators such as AND and OR.

For example, the following query will return all rows from the “employees” table where the “salary” is greater than 50000 and the “age” is greater than 30:

Syntax —

Select t1

from table_name

where t1 LIKE ‘%condition’

For Filtering using Comparison Based Operators —

Syntax —

Select t1

from table_name

Where t1 > 4

Using other comparison Operator —

Select t1

from table_name

Where t1 != ‘string’

Select t1,t2

from table_name

Where t1 == 17 AND t2 == ‘string’

Implementation —

-- Create a sample table
CREATE TABLE students (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  age INT,
  grade VARCHAR(10)
);

-- Insert sample data
INSERT INTO students (id, name, age, grade)
VALUES (1, 'John', 15, 'A'),
       (2, 'Jane', 16, 'B'),
       (3, 'Mike', 14, 'A'),
       (4, 'Emily', 17, 'C');

-- Filter data using WHERE clause and comparison operators
SELECT *
FROM students
WHERE age > 15;

SELECT *
FROM students
WHERE grade = 'A';

SELECT *
FROM students
WHERE age >= 14 AND age <= 16;

SELECT *
FROM students
WHERE name != 'Mike';

-- Filtering data using LIKE operator for pattern matching
SELECT *
FROM students
WHERE name LIKE 'J%';

SELECT *
FROM students
WHERE name LIKE '%m%';

SELECT *
FROM students
WHERE name LIKE 'J%n%';

Snippet —

That’s it for now.

Find Day 4 Below:

Let me know if you have questions in the comment section below. Subscribe/ Follow, Like/Clap as it would encourage me to write more in my free time

Stay Tuned!!

Read More —

11 most important System Design Base Concepts

1. System design basics

2. Horizontal and vertical scaling

3. Load balancing and Message queues

4. High level design and low level design, Consistent Hashing, Monolithic and Microservices architecture

5. Caching, Indexing, Proxies

6. Networking, How Browsers work, Content Network Delivery ( CDN)

7. Database Sharding, CAP Theorem, Database schema Design

8. Concurrency, API, Components + OOP + Abstraction

9. Estimation and Planning, Performance

10. Map Reduce, Patterns and Microservices

11. SQL vs NoSQL and Cloud

12. Most Popular System Design Questions

13. System Design Template — How to solve any System Design Question

14. Quick RoundUp : Solved System Design Case Studies

Some of the other best Series —

60 days of Data Science and ML Series with projects

30 Days of Natural Language Processing ( NLP) Series

30 days of Machine Learning Ops

30 days of Data Structures and Algorithms and System Design Simplified

60 Days of Deep Learning with Projects Series

30 days of Data Engineering with projects Series

Data Science and Machine Learning Research ( papers) Simplified **

100 days : Your Data Science and Machine Learning Degree Series with projects

23 Data Science Techniques You Should Know

Tech Interview Series — Curated List of coding questions

Complete System Design with most popular Questions Series

Complete Data Visualization and Pre-processing Series with projects

Complete Python Series with Projects

Complete Advanced Python Series with Projects

Kaggle Best Notebooks that will teach you the most

Complete Developers Guide to Git

Exceptional Github Repos — Part 1

Exceptional Github Repos — Part 2

All the Data Science and Machine Learning Resources

210 Machine Learning Projects

Tech Newsletter —

If you are interested, you can join my newsletter through which I send tech interview tips, techniques, patterns, hacks — Software Development, ML, Data Science, Startups and Technology projects to more than 30K readers. You can subscribe to Tech Brew :

For Python Projects —

For complete 60 days of Data Science and ML : Day 1 — Day 60 : Quick Recap of 60 days of Data Science and ML

Follow for more updates. Stay tuned and keep coding!

For other projects, tune to —

Build Machine Learning Pipelines( With Code)

Recurrent Neural Network with Keras

Clustering Geolocation Data in Python using DBSCAN and K-Means

Facial Expression Recognition using Keras

Hyperparameter Tuning with Keras Tuner

Custom Layers in Keras

Sql
Programming
Tech
Data Science
Machine Learning
Recommended from ReadMedium