Both LeetCode problems challenge you to manipulate data within a relational database using SQL. While seemingly similar, they focus on different aspects of data management:

  • LeetCode 1683: Invalid Tweets deals with identifying and handling invalid data. You’ll write a query to find tweets with specific criteria that mark them as invalid.
  • LeetCode 1378: Replace Employee ID With The Unique Identifier focuses on data transformation. Here, you’ll craft a query to replace existing employee IDs with a unique identifier within the database.

By tackling these problems, you’ll strengthen your skills in writing effective SQL queries for data cleaning and manipulation.

LeetCode 1683 - Invalid Tweets [SQL 5/50]

This is a short question, nothing to say here. 😂
Let’s jump right into the answer:

1
2
3
4
# Write your MySQL query statement below
SELECT tweet_id 
FROM Tweets
WHERE LENGTH(content) > 15

LeetCode 1378 - Replace Employee ID With The Unique Identifier [SQL 6/50]

We need a SQL query to achieve the following:

  • Show the unique ID for each user in a table.
  • If a user doesn’t have a unique ID, display NULL instead.
  • The order of the results doesn’t matter.

So I used a left join with aliases for the tables to improve readability:

1
2
3
4
# Write your MySQL query statement below
SELECT u.unique_id , name
FROM Employees e
LEFT JOIN EmployeeUNI u ON (e.id = u.id)

If you have any question please don’t hesitate to contact me.

See you in the next chapter