SQL Interview Question - Fetch Unique Values Without DISTINCT! #sqlinterview #coding

preview_player
Показать описание

============

============
The camera gear I use in my Videos

============
Connect With Me on My Social Media

============
FAQ
Which book to refer to learn -

============
AFFILIATE DISCLOSURE:
#rebellionrider

=============
I’ve got an SQL trick that will level up your data engineering game! 💻🚀

As someone who earned the Oracle SQL Expert 1z0-071 certification and recently published 'Mastering SQL Window Functions,' I’m always on the lookout for efficient and innovative ways to handle data. Today, I’m sharing a quick SQL trick that can fetch unique records from your database without using the DISTINCT keyword.

Imagine you need to fetch all the unique records from a column in your table. The usual approach would be to use the DISTINCT keyword. But here’s the twist—how do you achieve this without using DISTINCT, subqueries, or CTEs? 🤔

It’s simpler than you think. Use the GROUP BY clause! This groups the results by the column you want, giving you unique records effortlessly.

Fun fact: A study by Gartner reveals that effective data management, including SQL optimization, can improve decision-making efficiency by up to 33%. 🌐📊

Try it out and let me know if you knew this trick already! Comment below and share your thoughts or any other cool SQL tips you have! Let’s keep learning together. 🚀
Рекомендации по теме
Комментарии
Автор

Select first_name from employees
Union
Select first_name from employees;

harinadhbabu
Автор

select emp.first_name from
(select e.first_name, row_number() over (partition by first_name) as row_num from employees e) emp where row_num=1

abhisheksinha
Автор

I knew this.But when you said not using sub query distinct or cte, got confused a while.😅

sowmya
Автор

Without aggregate functions group by doesn't work

vishal.Ugrejiya
Автор

Which is a more efficient way to save costs?

aaroncode
Автор

Hi can I ask u something ?Did sql server can fail to pass exam?

yeshichoedon
Автор

I know before. Another techique is
SELECT a.first_name
FROM your_table_name a
LEFT JOIN your_table_name b
ON a.first_name = b.first_name AND a.rowid > b.rowid
WHERE b.first_name IS NULL;

ranajparida
Автор

Nice trick, I've used this. But effective

shekhark
Автор

To fetch last second record from table.

anirudh
Автор

i knew this, but is it cost effective ?

roshniagrawal