Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2019 February Database Design: Please do not use DISTINCT

Database Design: Please do not use DISTINCT

database design angry distinct

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

database design angry distinctI am telling you personally that I hate the use of DISTINCT.

DISTINCT used by those people, who are not sure about their data set or SELECT statement or JOINS.

Whenever I get any query with DISTINCT, immediately I suggest to remove it.

I asked to many developers that, does it makes sense to use DISTINCT or do we have any alternative?
Second, I asked that Why are you required to use DISTINCT.

Guys, what are you thinking? What was that answer?

Very simple, they keep quiet for a minute and were telling like: we are using to avoid duplicate result set.

This is not the correct answer for the use of DISTINCT.

Actually, most of developers are using DISTINCT because they want to hide their mistakes. They are writing incorrect joins and hiding duplication of data.

This is not only for database developer, DBA is a same responsible for this. The DBA must stop the duplication of data.

The DBA should give the answer that how duplicates data inserted in the database and who is responsible for that duplication.

Do you think, the use of DISTINCT is good for query performance?

My answer is simply no. Why, because it fetches unnecessary duplicate data and returns unique from it.

You should know the logical sequence of SQL Query execution. In the logical sequence, DISTINCT execute after SELECT means It checks all the data first and after that It avoids the duplicate data.

As I have raised a question for DISTINCT, few developers asked me to use GROUP BY instead of DISTINCT.

My simple answer was, Please do not use anything to remove duplicates from your result set.

Explicitly, you should remove the duplicate data and then also If you require to count few unique master group data, you can use GROUP BY instead of DISTINCT.

Feb 4, 2019Anvesh Patel
SQL Server: Auto Generate Database Detach and Attach ScriptsPostgreSQL: join_collapse_limit to force join order laid out by explicit JOINs
Comments: 1
  1. alexandre
    February 17, 2019 at 2:10 pm

    And there we go for the least effort. kudos for poiniting out to fix the real issue

    ReplyCancel

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

February 4, 2019 1 Comment Database DesigningAnvesh Patel, best practice, database, database concept, database research and development, database standards, Database Theory, database topic, dbrnd, DISTINCT, group by, performance, RDBMS
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....