Questions tagged [distinct]

The DISTINCT keyword is used to remove duplicate values from a result of a SQL or SPARQL query.

The DISTINCT keyword is used to remove duplicate values from a result of a SQL or SPARQL query.

The SQL 92 Standard defines DISTINCT as:

Two values are said to be not distinct if either: both are the null value, or they compare equal... Otherwise they are distinct. Two rows (or partial rows) are distinct if at least one of their pairs of respective values is distinct. Otherwise they are not distinct.

The SPARQL 1.1 Specification describes DISTINCT as:

The DISTINCT solution modifier eliminates duplicate solutions. Only one solution that binds the same variables to the same RDF terms is returned from the query.

5114 questions
1
vote
1 answer

SQL Remove row where value exist and subsequent column that has the value

I am trying to write a SQL statement that first gets only the distinct values of column 1, I then want to compare this with the same table but remove any rows that have a value in column 2 For example, the value 10142 in FieldID when I write a…
rdbmsNoob
  • 121
  • 1
  • 12
1
vote
2 answers

Is there a way to use dplyr distinct() to consider similar values as equal?

I have to do an analysis of scientific papers published in a list of over 20,000 journals. My list has over 450,000 records but with several duplicates (ex: a paper with more than one author from different institutions appear more than once). Well,…
André Brasil
  • 35
  • 1
  • 4
1
vote
2 answers

GROUP BY Syntax Mysql - Leaving out a groupable column

I have Table A with columns X,Y,Z. X is an FK, Y is a description. Each X has exactly one corresponding Y. So if X stays the same over multiple records, Y stays the same too. So there may be any number of records where X and Y are the same. Now I'm…
Narktor
  • 977
  • 14
  • 34
1
vote
1 answer

How Can We Count New Distinct Values group by date in SQL

I need to a distinct number of values in a column and group it by date, The real problem is the count should not include if it already occurred in a previous result. Eg: Consider the table tblcust Date Customers March 1 Mike March 1 …
1
vote
1 answer

Count Distinct Values in Column that contain same text string

I have a column with hundreds of items for each year. The items all start with a two digit year identifier, followed by a dash. Ex: "18-" , "19-" , "20-" After the dash is a 4+ digit unique number for the line item. However, for my main table there…
Ben.Name
  • 59
  • 1
  • 10
1
vote
2 answers

Distinct latest versions in mysql

I have a column in my mysql table something like this: appVersion 5.16.0.2889 5.16.0.2893 5.14.0 5.14.0.3 5.12.0.1 5.15.0.14 5.1.0.2 5.12.0.3 I want to get the distinct latest versions of this column segregated on the basis of the first two…
batman
  • 53
  • 8
1
vote
1 answer

DB2 - LISTAGG() with DISTINCT clause - doesn't work?

My query has a column with a small number of values in it, and I need to display them in a single field for each grouped result set - e.g. if I had an employee in 3 different departments, I'd want to see something like EMPID DEPTS …
JOATMON
  • 89
  • 2
  • 11
1
vote
1 answer

Distinct with Aggregation and Analytical functions

I'm just curious, is there a way to do this in Postgres? SUM(DISTINCT column_a) OVER(PARTITION BY column_b, column_c) Using DISTINCT causes an error: DISTINCT is not implemented for window functions
edavis
  • 51
  • 1
  • 9
1
vote
1 answer

mongodb get distinct items in array of subdocument array

What I have: I have a collection of patients, each patient has an array of subdocuments of treatments. each treatment has an array of diagnoses (which are simple string) What I want I want to get all the patients, without the treatments (but with an…
1
vote
3 answers

How do I count distinct to exclude a value?

Below is the different scales in a POS system. I am trying to count the number of distinct scales that are not 'MANUAL WT'. This is what I have, but it is returning 2 and not 6. count (distinct (case when d.SCALE_IN_ID != 'MANUAL WT' then 1 else 0…
sqlnoob
  • 19
  • 3
1
vote
1 answer

Ignoring duplicates based on a criteria except one

I have a table in ms access that gets updated daily. I need to remove all the duplicates posted within the same start date based on Policy number except to keep only 1 record with the highest number in the survey_number column. For Example, in the…
Shobi
  • 95
  • 1
  • 11
1
vote
3 answers

LINQ - Order By and Distinct by different fields. Skip & Take distinct values

I'm trying to ORDER BY some fields but SELECT DISTINCT by another field, and after that apply a Skip & Take Code: var result = entities.OrderBy(e => e.OrderField) .Select(e => e.SelectField) .Distinct() …
Matheus Simon
  • 668
  • 11
  • 34
1
vote
1 answer

Where to insert a CASE statement in SQL?

The issue here is that while this works in SSMS, it fails when I post it onto a website that uses an SQL processing tool. I have narrowed it down to the first bolded segment in the C3 section. Use the code before that and it gives an error (like it…
Calflamesfann
  • 133
  • 4
  • 16
1
vote
1 answer

Separate distinct values in to columns

Hi all I am quite new to SQL. I have a table (TABLE1) with two columns as below Name age -------- jim 18 jim 21 dave 18 dave 18 john 23 john 41 I need to create a view in SSMS which lists distinct ages for each name in a separate column as below…
Eskifan
  • 21
  • 2
1
vote
2 answers

Django Query, distinct on foreign key

Given these models class User(Model): pass class Post(Model): by = ForeignKey(User) posted_on = models.DateTimeField(auto_now=True) I want to get the latest Posts, but not all from the same User, I have something like this: posts =…
Reed Jones
  • 1,367
  • 15
  • 26