Skip to main content

SQL > SQL Commands > Distinct

SQL > SQL Commands > Distinct
In SQL, the DISTINCT keyword is used in the SELECT statement to retrieve unique values from a database table. Any value that has a duplicate will only show up once.

SQL में, डेटाबेस तालिका से अद्वितीय मानों को पुनः प्राप्त करने के लिए चयन कथन में DISTINCT कीवर्ड का उपयोग किया जाता है। कोई भी मूल्य जिसमें एक डुप्लिकेट है वह केवल एक बार दिखाएगा।

Syntax

SELECT DISTINCT "column_name"
FROM "table_name";
"table_name" is the name of the table where data is stored, and "column_name" is the name of the column containing the data to be retrieved.

"table_name" उस तालिका का नाम है जहां डेटा संग्रहीत किया जाता है, और "column_name" उस स्तंभ का नाम है जिसमें डेटा पुनर्प्राप्त किया जाना है।

Examples

The examples will use the following table:
Table Store_Information
Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

Example 1: Use DISTINCT on one column

To select all distinct stores in Table Store_Information, we key in,
SELECT DISTINCT Store_Name FROM Store_Information;
Result:
Store_Name
Los Angeles
San Diego
Boston

Example 2: Use DISTINCT on multiple columns

We can apply DISTINCT to multiple columns. If we want to get a list showing all unique combinations of stores and transaction dates, we would type in the following,

हम कई कॉलम में DISTINCT लगा सकते हैं। यदि हम स्टोर और लेन-देन की तारीखों के सभी विशिष्ट संयोजनों को दर्शाने वाली एक सूची प्राप्त करना चाहते हैं, तो हम निम्नलिखित में टाइप करेंगे,
SELECT DISTINCT Store_Name, Txn_Date FROM Store_Information;
Result:
Store_NameTxn_Date
Los AngelesJan-05-1999
San DiegoJan-07-1999
Los AngelesJan-08-1999
BostonJan-08-1999

Exercises

For these exercises, assume we have a table called Users with the following data:
Table Users
First_NameLast_NameBirth_DateGenderJoin_Date
SophieLeeJan-05-1960FApr-05-2015
RichardBrownJan-07-1975MApr-05-2015
JamalSantoOct-08-1983MApr-09-2015
CaseyHealySep-20-1969MApr-09-2015
JillWilkesNov-20-1979FApr-15-2015
1. Which of the following SQL statement is valid?
a) SELECT DISTINCT * FROM Users;
b) SELECT DISTINCT First_Name FROM Users;
c) SELECT DISTINCT First_Name Last_Name FROM Users;
2. What's the result of the following query?
SELECT DISTINCT Join_Date From Users;
3. What's the result of the following query?
SELECT DISTINCT Gender, Join_Date From Users;
1. b)
2. The result is:
Join_Date
Apr-05-2015
Apr-09-2015
Apr-15-2015
3. The result is:
GenderJoin_Date
FApr-05-2015
MApr-05-2015
MApr-09-2015
FApr-15-2015

Comments

Popular posts from this blog

Excel VBA Code For Clear Cell एक्सेल VBA कोड क्लियर सेल के लिए

# VBA Code to Clear Cell :- To  clear cells using VBA , use a statement with the following structure:- VBA का उपयोग :-  सेल  को साफ करने के लिए Cells.Clear VBA Statement Explanation Item:  Cells. VBA Construct:  Range object. Description:  Range object representing the cells you want to clear. You can usually return a Range object with constructs such as the Worksheet.Range, Worksheet.Cells (with Range.Item), Range.Offset, Range.Resize or Application.ActiveCell properties. If you explicitly declare an object variable to represent Cells, use the Range object data type. Item:  Clear. VBA Construct:  Range.Clear method. Description:  The Range.Clear method clears the Range object you specify (Cells). Range.Clear clears the entire Range object, including values, formulas and formatting. VBA स्टेटमेंट स्पष्टीकरण 1. आइटम: सेल। VBA निर्माण: रेंज ऑब्जेक्ट। विवरण: रेंज ऑब्जेक्ट उन कोश...

SQL > SQL Commands > Select

SQL > SQL Commands  >  Select The  SELECT  statement in SQL is used to retrieve data from a relational database. SQL में SELECT स्टेटमेंट का उपयोग रिलेशनल डेटाबेस से डेटा को पुनः प्राप्त करने के लिए किया जाता है। Syntax Number of Columns SQL Syntax 1 SELECT "column_name" FROM "table_name"; More Than 1 SELECT "column_name1"[, "column_name2"] FROM "table_name"; All SELECT * FROM "table_name"; "table_name" is the name of the table where data is stored, and "column_name" is the name of the column containing the data to be retrieved. "table_name" उस तालिका का नाम है जहां डेटा संग्रहीत किया जाता है, और "column_name" उस स्तंभ का नाम है जिसमें डेटा पुनर्प्राप्त किया जाना है। To select more than one column, add a comma to the name of the previous column, and then add the column name. If you are selecting three columns, the syntax will be, एक से अधिक कॉलम का चयन...

Excel Simple Formulas एक्सेल सरल सूत्र

Excel uses Standard Operators for formulas, such as a Plus Sign (+) for Addition , a Minus Sign (-) for Subtraction , an Asterisk Sign (*) for Multiplication , a Forward Slash Sign (/) for Division , and a Caret Sign (^) for Exponents . All these are Mathematical Operators and in Excel All Formulas must begin with an Equals Sign (=). एक्सेल सूत्रों के लिए मानक ऑपरेटर का उपयोग करता है, जैसे अतिरिक्त के लिए प्लस साइन (+), घटाव के लिए एक ऋण चिह्न (-), गुणा के लिए एक तारांकन चिह्न (*), प्रभाग के लिए एक फॉरवर्ड स्लैश साइन (/), और एक कैरेट साइन (^) एक्सपोनेंट्स के लिए। ये सभी गणितीय ऑपरेटर हैं और एक्सेल में सभी सूत्रों को बराबर चिह्न (=) से शुरू होना चाहिए। Addition + Subtraction - Multiplication * Division / Exponents ^ For example  :-