Retrieve unique records in SQL WITHOUT using distinct

 Dataset:

Create table statement


Create table test
(
id int,
Name varchar(10)
)


Run the below commands more than once


Insert into test
VALUES
(1,'Rohit')


Insert into test
VALUES
(2,'Rahul')


Query with Distinct














Query without distinct

















UNION always removes duplicates from the output. So, apply union to the same query so that it will return the unique records in the output


Detailed explanation: https://youtu.be/hcxogMdSRQA





Comments

Popular posts from this blog

50 Essential SQL Questions to Land Your Dream Job

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs