Menu

SQL

How to remove duplicate rows in MySQL

How to remove duplicate rows in MySQL?

Problem Given a table in MySQL, how do you remove duplicate rows? Input first_name last_name email John Doe [email protected] Jane Smith [email protected] John Doe [email protected] Bob Johnson [email protected] Alice Williams [email protected] Jane Smith [email protected] Try Hands-On: Fiddle Create Input Table: Gist Desired Output first_name last_name email John Doe [email protected] Jane Smith [email protected] Bob Johnson [email protected]

How to remove duplicate rows in MySQL? Read More »

How to split values to multiple rows in SQL

How to split values to multiple rows in SQL?

Problem How to split values to multiple rows in SQL? Input To illustrate this problem, let’s create a sample input table named “Sales” with some data. The table will have two columns: “Date” and “Amount.” id vals 1 value1,value2,value3 2 value4,value5 3 value6 Try Hands-On: Fiddle Create Input Table: Gist Desired Output id split_value 1 …

How to split values to multiple rows in SQL? Read More »

How to calculate running total in SQL Server

How to calculate running total in SQL Server?

Problem You need to calculate a running total in SQL Server and provide a solution that is also reproducible in MySQL. Input To illustrate this problem, let’s create a sample input table named “Sales” with some data. The table will have two columns: “Date” and “Amount.” Date Amount 2023-09-01 100.00 2023-09-02 75.50 2023-09-03 50.25 2023-09-04 …

How to calculate running total in SQL Server? Read More »

How to insert into a table or update if exists in MySQL

How to insert into a table or update if exists in MySQL?

Problem You need to calculate a running total in SQL Server and provide a solution that is also reproducible in MySQL. Input employee_id first_name last_name salary 1 John Doe 50000.00 2 Jane Smith 60000.00 3 Bob Johnson 55000.00 Try Hands-On: Fiddle Desired Output On inserting a new row, if the entry already exists, it should …

How to insert into a table or update if exists in MySQL? Read More »

How to get the rows which have the max value for a column for each group in another column in SQL?

Problem You want to find the rows that have the maximum value for a specific column within each group in another column. For example, you have a table with data about products and their prices, and you want to find the most expensive product in each category. Input product_id product_name category_id price 1 Product A …

How to get the rows which have the max value for a column for each group in another column in SQL? Read More »

SQL Window Functions Exercises

SQL Window Functions Exercises – Practice to perfection

SQL window functions is considered a ‘hard’ concept in SQL. This set of exercises is designed to challenge your SQL muscle and help internalize data wrangling using window functions in SQL. The questions are of three levels of difficulty: Easy, Intermediate and Hard. If you haven’t read the tutorial yet, read SQL Window Functions – …

SQL Window Functions Exercises – Practice to perfection Read More »

SQL Window Functions

SQL Window Functions – Made simple and intuitive

SQL window functions is one of the advanced concepts, understanding which will give you the ability to do complex data wrangling and transformations in SQL. In this guide, we will intuitively understand how window functions work in a way you will never forget. Don’t memorize anything, just read through and you will clearly understand how …

SQL Window Functions – Made simple and intuitive Read More »

SQL Tutorial

SQL Tutorial – A Simple and Intuitive Guide to the Structured Query Language

SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs. In this tutorial, let’s get started with the basics of SQL. 1. Why you should learn SQL? First, let’s understand …

SQL Tutorial – A Simple and Intuitive Guide to the Structured Query Language Read More »

SQL Operators – Understanding SQL Operators with Examples and Syntax

Welcome to our comprehensive guide on SQL (Structured Query Language) operators! In this blog post, we’re going to break down the various operators used in SQL, their syntax, and how to use them effectively. You will also look at some examples, working with a hypothetical data set to give you a hands-on understanding. Let’s dive …

SQL Operators – Understanding SQL Operators with Examples and Syntax Read More »

SQL Primary Key: The Cornerstone of Database Integrity

Primary Key a cornerstone for maintaining data integrity and building complex database relationships. Introduction Data is at the heart of any application, and the key to managing this data effectively lies in the use of a well-structured database. SQL, or Structured Query Language, is the standardized language used to manage and manipulate relational databases. It …

SQL Primary Key: The Cornerstone of Database Integrity Read More »

SQL DROP TABLE – An Expert’s Guide to SQL DROP TABLE Command

Let’s deep dive into one of SQL’s essential commands – DROP TABLE. What is the DROP TABLE Command? The DROP TABLE command in SQL is a Data Definition Language (DDL) statement used to remove a table definition along with all the data, indexes, triggers, constraints, and permission specifications for that table. Essentially, the command completely …

SQL DROP TABLE – An Expert’s Guide to SQL DROP TABLE Command Read More »

Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science