Invalid Tweets
Find tweets whose content is longer than 15 characters.
Start practiceProblem statement
Prompt
Given the tweets table below, write a query that returns the tweet_id of every tweet whose content is longer than 15 characters.
- A tweet is _invalid_ when
LENGTH(content) > 15. - Output a single column:
tweet_id.
Example
| tweet_id | content |
|---|---|
| 1 | Let us code |
| 2 | More than fifteen chars! |
Expected result:
| tweet_id |
|---|
| 2 |
Constraints
tweets.tweet_idis the primary key.
Tips
- In SQLite,
LENGTH(content)counts characters — exactly what we want here.
Schema
CREATE TABLE tweets (
tweet_id INTEGER PRIMARY KEY,
content TEXT NOT NULL
);
Sample data
INSERT INTO tweets (tweet_id, content) VALUES
(1, 'Let us code'),
(2, 'More than fifteen chars!'),
(3, 'short'),
(4, 'This one is definitely way too long to be a valid tweet');
Additional hidden fixtures are applied during validation to test edge cases.
Solution
One correct approach — try solving it yourself in the practice editor first, then compare. There is usually more than one valid solution.
-- Reference: tweets longer than 15 characters.
SELECT tweet_id
FROM tweets
WHERE LENGTH(content) > 15
ORDER BY tweet_id;
Key concepts
- LENGTH
- String comparison
Related questions
- easyArticle Views IFind the authors who viewed their own articles at least once.
- easyBig CountriesFind countries with a large area or population.
- easyFind Customer RefereeFind customers who are not referred by customer id 2.
- easyRecyclable and Low Fat ProductsFind the ids of products that are both low fat and recyclable.