SQL

Categories: Code Problem / Data Structures and Algorithms / Recursion (32) Code Problem / Data Structures and Algorithms / Binary Search (30) Code Problem / Data Structures and Algorithms / Linked Lists (26) Code Problem / Data Structures and Algorithms / Backtracking (26) Code Problem / Data Structures and Algorithms / Stacks and Queues (25) Code Problem / Data Structures and Algorithms / Hashing (24) Databases / SQL / Backup and Recovery (19) Code Problem / Data Structures and Algorithms / Arrays and Strings (19) Databases / SQL / Database Normalization (18) Code Problem / Data Structures and Algorithms / Time Complexity (17) Databases / SQL / Locking (16) Databases / SQL / Replication (15) Databases / SQL / SQL Queries (13) Code Problem / Data Structures and Algorithms / Graphs (13) Databases / SQL / Database Security (13)  More...

Recent solutions:

Check these solutions from our community:
Databases / SQL DifficultyHard SQL
This technical problem deals with writing a SQL query to find the number of distinct values in each column of a table. The input is a table with two columns, and the output is the number of distinct values in each column.
About this solution: The solution above is optimal because it uses the COUNT function with the DISTINCT keyword. This will count the number of unique values in each column.
Jan 29
Databases / SQL DifficultyHard SQL
Write a SQL query to find employees who have been with a company for more than 5 years. The table to query has the following schema: (name, department, start_date). The query should return the (name, department, start_date) for each employee meeting the 5 year criteria.
About this solution: This solution is correct and demonstrates a good understanding of SQL.
Jan 29
Databases / SQL DifficultyHard SQL
Write a SQL query to find all pairs of rows (a, b) such that a is in table A, b is in table B, and a and b have the same value for column C.
About this solution: This solution is correct and demonstrates a good understanding of SQL. The approach is straightforward and easy to follow.
Jan 28
Databases / SQL DifficultyHard SQL
The technical problem is how to write a SQL query that returns the top 3 most populous countries. The example output is China, India, United States.
About this solution: The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by population in descending order and then limit the results to the top 3.
Jan 28
Databases / SQL DifficultyHard SQL
Write a SQL query to find the top 10 customers by total spent.
About this solution: The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by total_spent in descending order and then limit the results to the top 10 customers.
Jan 28
Databases / SQL DifficultyHard SQL
To replicate a database across multiple servers, you would need to set up a master server with the database, and then set up replication on the other servers. This would allow the other servers to have copies of the database, which would be updated whenever the master server's database is updated.
About this solution: The candidate's solution is incomplete. It does not address how to keep the databases in sync or how to handle write conflicts. Additionally, the candidate does not mention any performance implications of this solution.
Jan 27
Databases / SQL DifficultyHard SQL
Update customer credit score on address update: - Given a table of customer data with name, address, credit score, and date of last address update columns, - write a trigger that will automatically update the customer's credit score whenever their address is updated. - Output will be the customer table with updated credit scores.
About this solution: The trigger above will update the credit score of the customer whenever their address is updated. This is a good solution that solves the problem. The trigger is optimal because it will only update the credit score of the customer whose address was updated.
Jan 27
Databases / SQL SQL
Write a SQL query to find the names of the two highest scoring individuals in a table of data.
About this solution: The candidate's solution is correct and demonstrates a good understanding of SQL.
Jan 27