SQLite query: select id, otherid, score from similarities order by score desc limit 101…
- User
SQLite query: select id, other_id, score from similarities order by score desc limit 101
First few results:
github-actions_service-containers-docker.md github-actions_postgresq-service-container.md 0. github-actions_postgresq-service-container.md github-actions_service-containers-docker.md 0. llms_nanogpt-shakespeare-m2.md llms_training-nanogpt-on-my-blog.md 0. llms_training-nanogpt-on-my-blog.md llms_nanogpt-shakespeare-m2.md 0.
I want to dedupe on the fact that there are always two pairs with the same score - I just want the first of each pair
- Assistant
You're seeing pairs of rows with essentially the same information, but theidandother_idcolumns are flipped. One way to dedupe these is by making sure that theidis always smaller than theother_id, then filter based on this criteria.
Here's how you can modify the SQL query to achieve this:
────────────────────────────────────────────────────────────────────
sqlCopy codeSELECT id, other_id, score FROM similarities WHERE id < other_id ORDER BY score DESC LIMIT 100;
This ensures you only get the first of each pair by forcing always be the smaller value. The LIMIT has been changed to 100 to retrieve the top 100 pairs without duplicates.
- User
with top_similarities as ( select id, other_id, score from similarities where id < other_id order by score desc ), til_details as ( select path, title, || topic || '/' || slug as url from til ) select t1.title, t1.url, t2.title, t2.title, t1.title, t1.url, t2.title, t2.url, t1.title, t1.url, t2.title, t2.title, t1.title, t1.url, t2.title, t2.url, score from til_details t1 join top_similarities on id = t1.id join til_details t2 on other_id = t2.id
no such column: t1.id
Fix it
- Assistant
The error you're seeing is because there's noidcolumn directly in thetil_detailsCTE, so you can't reference it ast1.idin the join.
Instead, you need to include theidin thetil_detailsCTE. Here's the modified query:
────────────────────────────────────────────────────────────────────
sqlCopy codeWITH top_similarities AS ( SELECT id, other_id, score FROM similarities WHERE id < other_id ORDER BY score DESC ), til_details AS ( SELECT id, path, title, || topic || '/' || slug AS url FROM til ) SELECT .title, .url, .title, .url, top_similarities.score FROM til_details t1 JOIN top_similarities ON t1.id = top_similarities.id JOIN til_details t2 ON top_similarities.other_id = t2.id;
This should resolve the "no such column" error.