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
3 answers

How to select the column name that contains maximum number of distinct values? - Oracle SQL

Here is my current query: SELECT c.COLUMN_NAME, t.NUM_ROWS FROM ALL_TAB_COLUMNS c INNER JOIN ALL_TABLES t ON t.OWNER = c.OWNER AND t.TABLE_NAME = c.TABLE_NAME WHERE c.TABLE_NAME='MY_TABLE_NAME' AND c.OWNER = 'MY_SCHEMA_NAME' What this does is…
1
vote
1 answer

SQL Server DISTINCT

SELECT dbo.CLIENTREP.ref, dbo.REP2.ref FROM dbo.CLIENTREP FULL OUTER JOIN dbo.REP2 ON (dbo.REP2.ref = dbo.CLIENTREP.ref) WHERE dbo.REP2.ref is null OR dbo.CLIENTREP.ref IS NULL; How can I specify that only DISTINCT dbo.CLIENTREP.ref and…
Michael
  • 13,838
  • 18
  • 52
  • 81
1
vote
5 answers

Two tables, distinct license number to return

Have two tables which display owner information for their registered dogs; one for 2018 and another for 2019. Each table has the same columns, names, etc. I need to only list the one full record by the license number. For example, the dog may not…
user1424532
  • 95
  • 2
  • 12
1
vote
4 answers

Sql statement question

I have a table, which contains logs and has the following scheme: USER | DATE | LOG x x x ... Now, I want to make ONE query to retrieve every (USER, DATE) pair, where DATE is the latest for this user. I was thinking about something like…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
1
vote
5 answers

SQL Server - updating distinct values

I have 3 columns of data: Column1 has duplicate values eg a a b b c c Column2 has all NULL values Column3 has other data that is not really important I want to update Column2 with a value eh Hello but only for 1 instance of each value for column1.…
DS123
  • 11
  • 2
1
vote
2 answers

kotlin distinct() or distinctBy {} from 2 existing arrays

Trying to understand distinct() and distinctBy function to check duplicates. when i try "distinct" with list of strings, it works fine. when i try it with Type "Any" with custom class NO luck :( can anyone please help me understand? var a =…
Terry
  • 107
  • 2
  • 11
1
vote
2 answers

Selecting distinct 5 columns combination in mysql

I have a mysql table that looks like this: Col 1 is UNIQUE. 1 value1 value2 0 2 2 value1 value2 1 3 3 value3 value4 3 2 4 value4 value5 4 1 5 value3 value4 3 1 I need a query to select all the…
Jayan Dev
  • 67
  • 1
  • 10
1
vote
1 answer

Are postgresql `SELECT DISTINCT` queries deterministic?

Are Postgres SELECT DISTINCT queries deterministic? Will SELECT DISTINCT somecolumn FROM sometable return the same result (including order) if the table (and entire database) goes unchanged? In the Select Query Documentation the Description section…
DannyDannyDanny
  • 838
  • 9
  • 26
1
vote
1 answer

How can I select distinct rows with max values on another column in Access 2016

I am using Access 2016 as database tool and want to be able to retrieve the latest "Version" of an "Entry" from a "DataTable". Each of these Parameters (amongst others) are separate columns in the DataTable. When I split the nested query into to…
FunCoder
  • 33
  • 3
1
vote
1 answer

Make a distinct select in SQL,selecting all "categoria" except one distincted

i want to select "categoria",idjogo where idjogo=NULL, except the hentai. the hentai i want to select is the one where idjogo=100;
1
vote
4 answers

COUNT total distinct values existing in multiple columns oracle

I have below table and i want to count distinct values that cross between two columns. ID_DATE DESCRIPT1 DESCRIPT2 20191001 A R 20191001 D B 20191001 B D 20191001 A B 20191002 A …
Omari Victor Omosa
  • 2,814
  • 2
  • 24
  • 46
1
vote
4 answers

How to avoid DISTINCT in a query that joins multiple tables?

I want to avoid using DISTINCT and produce the same result for queries that join multiple tables. Without DISTINCT, it produces the same row multiple times. I already tried looking up how to avoid DISTINCT, but nothing seems to work for me,…
user7600592
1
vote
1 answer

How to create partial index on table with where clause in sqlite?

I have a table with 2 million rows. I have created index on (expression of an unique column). That expression will map the column's value to a lower number space, meaning the outcome of that expression is not unique. Now I want to create index on…
PoomaniGP
  • 80
  • 1
  • 1
  • 11
1
vote
1 answer

select distinct Id with different names asociated and select also the names related to the id selected :/

My title sounded like a tongue twister, so let me explain myself better. I have a table with very bad data quality in which I have the following case: CustomerId CustomerName 1 Jhon 1 Mary 2 Tom CustomerId is not the key…
JudithMCA
  • 61
  • 7
1
vote
2 answers

LINQ - Query with distinct/GroupBy on multiple properties problem

I have some data stored in an EntitySet of my domainContext where I want to select out just parts of it. Problem is that I'm getting all the CageNames - and not just the "New" ones with the highest date. This is the data: SiteId CageId CageName …
1 2 3
99
100