A newsroom asks for its latest three published articles with their tags. The query joins tags before applying a three-row limit. One article has three tags, so the report returns only that article. Decide what the limit counts before building the list an AI assistant will summarize.

Reference: PostgreSQL SELECT documentation. PostgreSQL describes how LIMIT selects a subset of the query result rows.

Choose what the limit counts

When the requirement is three articles, select the three article records under a defined publication rule first, then attach tags. The resulting rows may number more than three until the application groups them by article. Another suitable design can aggregate the tags to one row per article before applying the limit. If the requirement instead means the three newest tag assignments, a tag-level limit can be appropriate. Write the unit of selection and a stable order in the export contract.

Test a story with several tags

Use a fictional archive with three eligible articles. Give the newest three tags, the next one tag and the third none. A raw joined result limited to three rows can repeat the newest record and omit the rest. Test the intended report using a selection that includes all three articles and preserves the untagged one. If the final join is meant to keep untagged articles, verify that its behavior does so. Track selected article IDs separately from the number of rows the join produced.

Do not tidy the result by dropping duplicate rows after the limit and calling the shorter list complete. Test that every article the selection chose is represented, and verify how tags are ordered in its display.

Keep a one-to-many fixture in the checks whenever the report adds another related table.

Add a draft article newer than every published record in the fixture. It should not displace an eligible story merely because the sort and limit ran before the publication filter.