Meta: Threads Posts Cut Off in the Feed Preview

Easy
752.

Meta: Threads Posts Cut Off in the Feed Preview

EasyStrings

MySQL

On a compact feed card, Threads shows only the first 40 characters of a post and adds an ellipsis. A designer wants to see exactly what those cards will look like.

Return every post whose body is longer than 40 characters, with the columns post_id and preview — the first 40 characters of the body followed by ... (three dots). A post of exactly 40 characters fits and is not returned. Return the rows ordered by post_id.

A practice scenario set at Meta: the tables and data are invented, and this is not a question from, or endorsed by, Meta.

Tables

Table: ThreadsPost

ColumnType
post_idint
author_handlevarchar
bodyvarchar
posted_atdatetime

Primary key: post_id.

One row per Threads post. body is plain text (letters, digits, spaces, punctuation) and is never NULL.

Example

The rows must come back in the order shown.

ThreadsPost

post_idauthor_handlebodyposted_at
1chai.coderShipping a new feature today, wish me luck2025-08-01 09:15:00
2mumbai.rainsWho else is watching the match tonight??2025-08-01 19:40:00
3tabs.foreverHot take: tabs beat spaces, fight me2025-08-02 11:05:00
4run.priyaFinished my first marathon in under five hours!!2025-08-03 07:30:00
5late.night.devChai or coffee for a late night debug run2025-08-03 23:55:00

Output

post_idpreview
1Shipping a new feature today, wish me lu...
4Finished my first marathon in under five...
5Chai or coffee for a late night debug ru...
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

Meta: Threads Posts Cut Off in the Feed Preview

On a compact feed card, Threads shows only the first 40 characters of a post and adds an ellipsis.

  • Difficulty: Easy
  • Topics: Strings
  • Dialect: MySQL
  • Problem: #752

Problem statement

On a compact feed card, Threads shows only the first 40 characters of a post and adds an ellipsis. A designer wants to see exactly what those cards will look like.

Return every post whose body is longer than 40 characters, with the columns post_id and preview — the first 40 characters of the body followed by ... (three dots). A post of exactly 40 characters fits and is not returned. Return the rows ordered by post_id.

A practice scenario set at Meta: the tables and data are invented, and this is not a question from, or endorsed by, Meta.

Tables

Table: ThreadsPost

ColumnType
post_idint
author_handlevarchar
bodyvarchar
posted_atdatetime

Primary key: post_id.

One row per Threads post. body is plain text (letters, digits, spaces, punctuation) and is never NULL.

Examples

Example 1

ThreadsPost

post_idauthor_handlebodyposted_at
1chai.coderShipping a new feature today, wish me luck2025-08-01 09:15:00
2mumbai.rainsWho else is watching the match tonight??2025-08-01 19:40:00
3tabs.foreverHot take: tabs beat spaces, fight me2025-08-02 11:05:00
4run.priyaFinished my first marathon in under five hours!!2025-08-03 07:30:00
5late.night.devChai or coffee for a late night debug run2025-08-03 23:55:00

Output

post_idpreview
1Shipping a new feature today, wish me lu...
4Finished my first marathon in under five...
5Chai or coffee for a late night debug ru...

How to solve Meta: Threads Posts Cut Off in the Feed Preview

Two string functions do the work. The filter is a length test: CHAR_LENGTH(body) > 40 keeps only the posts the card would cut, and the strict > lets a post of exactly 40 characters through untouched, since it fits. The preview is the visible part plus the marker: LEFT(body, 40) takes the first 40 characters and CONCAT(…, '...') appends the three dots.

CHAR_LENGTH counts characters, while LENGTH counts bytes in MySQL; for this plain ASCII text they agree, which is why the alternative's LENGTH(body) >= 41 gives the same rows, and SUBSTRING(body, 1, 40) is the same cut as LEFT. On text with emoji or Devanagari the byte count would be larger, so CHAR_LENGTH is the safer habit.

The statement fixes the order, so the query ends with ORDER BY post_id. It is one scan of the table.

Reference solution (MySQL)

SELECT post_id, CONCAT(LEFT(body, 40), '...') AS preview
FROM ThreadsPost
WHERE CHAR_LENGTH(body) > 40
ORDER BY post_id

Another way

SELECT post_id, CONCAT(SUBSTRING(body, 1, 40), '...') AS preview FROM ThreadsPost WHERE LENGTH(body) >= 41 ORDER BY post_id

← Meta: Ad Accounts That Overspent Their September Limit · Meta: Messenger Video Call Minutes by Day of the Week →