2 min
How to sort multiple columns in SQL and in different directions?
Problem How to sort multiple columns in SQL and in different directions? Input Let’s create a table named Employees with columns: id, first_name, last_name,...
2 min
Problem How to sort multiple columns in SQL and in different directions? Input Let’s create a table named Employees with columns: id, first_name, last_name,...
2 min
Problem To count the number of work days between two dates, taking into account weekends (Saturdays and Sundays) and assuming no holidays. Input We...
2 min
Problem Given a table with multiple columns, compute the maximum value for each row across the specified columns. Input -- Create an example table...
2 min
Problem: How to use the GROUP BY clause on multiple columns in SQL? Input: Let’s assume we have a table called Orders with columns...
3 min
Problem You need to retrieve a list of dates between two specified dates. Input First, let’s create a table and insert some sample data...
3 min
The difference between CROSS JOIN and INNER JOIN in SQL The question here is about the difference between a CROSS JOIN and an INNER...
2 min
Problem You have two tables, tableA and tableB. You want to retrieve all records from tableA that do not have a matching record in...
3 min
Problem How to access the “previous row” value in a SELECT statement in SQL? Input id sale_date units_sold 1 2023-01-01 10 2 2023-01-02 15...
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...