2 min
How to exclude a column using select * except column?
Problem You have a database table, how to select all columns except specific columns mentioned by the user? Example Syntax: SELECT * [except columnA]...
2 min
Problem You have a database table, how to select all columns except specific columns mentioned by the user? Example Syntax: SELECT * [except columnA]...
2 min
Problem Often when dealing with database records, you might encounter a situation where you want to group records based on a specific column but...
2 min
Problem Let’s understand the difference between UNION and UNION ALL in SQL with an example. Input Let’s create a table named fruits with columns...
2 min
Problem Let’s see how to find duplicate values in an SQL table. Input id name enrollment_number 1 Alice ENR123 2 Bob ENR124 3 Charlie...
2 min
Problem You have a table with a column where some rows contain NULL values or empty strings. You want to retrieve rows where this...
2 min
Problem You have a table with multiple records. For each distinct value in one of the columns (i.e., each ‘group by’ group), you want...
2 min
Problem You have a table with multiple rows of data for each unique identifier and you want to concatenate the values of these rows...
2 min
Problem How to escape a single quote in SQL Server, with a solution that is also reproducible in MySQL? For example, let’s try to...
4 min
Problem What is the difference between INNER JOIN, OUTER JOIN and FULL OUTER JOIN? Input Let’s create three example tables, employees, departments, and projects,...
3 min
Problem How to select a random row using SQL? Input employee_id first_name last_name salary 1 John Doe 50000 2 Jane Smith 60000 3 Michael...
2 min
Problem How to randomly select rows quickly from a large table in MySQL? Input employee_id first_name last_name department salary 1 John Doe HR 50000.00...
2 min
Problem Given a table, how to efficiently convert rows to columns? So that, the records in a given row become column names and the...
2 min
Problem Given a table in MySQL, how do you remove duplicate rows? Input first_name last_name email John Doe john.doe@email.com Jane Smith jane.smith@email.com John Doe...
2 min
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...
3 min
Problem You need to calculate a running total in SQL Server and provide a solution that is also reproducible in MySQL. Input To illustrate...
2 min
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...
2 min
Problem How to do a FULL OUTER JOIN in MySQL? Let’s create two example tables, employees and departments, and insert some data into them....
3 min
Problem You want to find the rows that have the maximum value for a specific column within each group in another column. For example,...
2 min
Problem You need to concatenate text from multiple rows into a single text string, for every group present in another column using SQL. For...
2 min
Problem How to switch rows and columns in SQL so that the rows and columns are interchanged? Given a table named Students with columns...