SQLHUB Telegram 2050
🧩 SQL хитрый трюк

Хотите быстро найти дубликаты в таблице — но не просто значения, а ещё и сразу оставить только уникальные строки?

Вместо сложных подзапросов используйте `ROW_NUMBER()` с PARTITION BY:


WITH numbered AS (
SELECT
id,
email,
ROW_NUMBER() OVER (PARTITION BY email ORDER BY id) AS rn
FROM users
)
SELECT id, email
FROM numbered
WHERE rn = 1;


📌 Что происходит:
- PARTITION BY email группирует строки по email
- ROW_NUMBER() нумерует их внутри группы
- WHERE rn = 1 оставляет только первую запись (а все дубликаты убираются)

💡 Так можно элегантно чистить таблицы от дублей без лишних вложенных запросов.

@sqlhub
👍16🔥83🥰1



tgoop.com/sqlhub/2050
Create:
Last Update:

🧩 SQL хитрый трюк

Хотите быстро найти дубликаты в таблице — но не просто значения, а ещё и сразу оставить только уникальные строки?

Вместо сложных подзапросов используйте `ROW_NUMBER()` с PARTITION BY:


WITH numbered AS (
SELECT
id,
email,
ROW_NUMBER() OVER (PARTITION BY email ORDER BY id) AS rn
FROM users
)
SELECT id, email
FROM numbered
WHERE rn = 1;


📌 Что происходит:
- PARTITION BY email группирует строки по email
- ROW_NUMBER() нумерует их внутри группы
- WHERE rn = 1 оставляет только первую запись (а все дубликаты убираются)

💡 Так можно элегантно чистить таблицы от дублей без лишних вложенных запросов.

@sqlhub

BY Data Science. SQL hub


Share with your friend now:
tgoop.com/sqlhub/2050

View MORE
Open in Telegram


Telegram News

Date: |

End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. A Telegram channel is used for various purposes, from sharing helpful content to implementing a business strategy. In addition, you can use your channel to build and improve your company image, boost your sales, make profits, enhance customer loyalty, and more. So far, more than a dozen different members have contributed to the group, posting voice notes of themselves screaming, yelling, groaning, and wailing in various pitches and rhythms. During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month. Matt Hussey, editorial director at NEAR Protocol also responded to this news with “#meIRL”. Just as you search “Bear Market Screaming” in Telegram, you will see a Pepe frog yelling as the group’s featured image.
from us


Telegram Data Science. SQL hub
FROM American