Questions tagged [distinct]
The distinct tag has no summary.
149 questions
1 vote
1 answer
66 views
Select values from two columns without repetition
I have these two tables in a SQLite 3 database: The first table contains four points in a 2D space. The columns X and Y are the coordinates. The second table represents the segments that form a ...
17 votes
1 answer
2k views
Union does not always eliminate duplicates
I have the following query and expect that as a result I will have a list of IDs without duplicates. But sometimes it produces duplicates (1-2 on 4 million rows). Why can it happen? I run it with the ...
1 vote
1 answer
73 views
Poor performance bucketing historical data with DISTINCT
I'm running into performance problems with a query that buckets a set of historical records of daily counts into a form that can be rendered easily as a daily graph. Context Essentially, the table in ...
-1 votes
1 answer
197 views
What happened to Oracle's COUNTDISTINCT() function? [closed]
I need the count of unique values, and am trying to use Oracle's COUNTDISTINCT() function to obtain that: select COUNTDISTINCT(a.m_label) from user_rep a, user_group_rep b, trn_grp_rep c ...
1 vote
1 answer
95 views
Finding the distinct values in an array of documents
I've got a database full of documents which each contain a collection of transactions: [ { "key": 1, "data": [ { "trans": 1, "uid&...
2 votes
1 answer
521 views
Emulate Loose Index Scan for multiple columns with alternating sort direction
A while back I asked this question about efficiently selecting unique permutations of columns in Postgres. Now I have a follow-up question regarding how to do so, with the addition of being able to ...
0 votes
2 answers
380 views
Selecting a count of distinct logins per day
I have an activity_log table that I need to derive a basic output of how many distinct users logged in that day, and sum up them up day by day. The table logs all actions of a user and will have ...
0 votes
1 answer
107 views
Distinct based on window function (sort curiosity or wrong problem approach)
A lot of values are stored in values. The data is in a hierarchical order, so there could be a probe, on which some measurements have been performed. Many points have been archived with strain and ...
1 vote
2 answers
958 views
Window functions and distinct
I have the following table. Column | Type | Collation | Nullable | Default ----------+-----------------------------+-----------+----------+--------- code | text ...
0 votes
0 answers
303 views
Optimizing SELECT COUNT(DISTINCT) on a table increasing daily
Let's say we have a table Daily_users which has the columns student_id, school_id, grade, timestamp. We collect usage data of students daily and so the table grows daily (note that there could be ...
0 votes
1 answer
158 views
The most recent rows in for each type/agent
I have a table (still on MySQL 5.7) with lots of data. This table is written by some scripts. It works like a "checkin", where each agent is checking in in some period of time. It looks like ...
0 votes
1 answer
66 views
Select distinct
I had some confusion regarding distinct keyword... For example Table test has 5 columns a b c d e, and column a has repeated value, and I want to use distinct keyword to get distinct values while also ...
19 votes
1 answer
1k views
DISTINCT not reducing two equal values to one
Can anyone explain the below situation, where two seemingly equal values are not reduced by DISTINCT? The query above is SELECT DISTINCT name FROM master.sys.dm_os_spinlock_stats where name = '...
2 votes
1 answer
1k views
DISTINCT gives duplicate values
Can it be considered a bug? This query gives duplicate values despite DISTINCT: select distinct '1' from ( select * from dual connect by level <= 10 ) order by dbms_random.value fetch first 10 ...
1 vote
1 answer
2k views
Insert rows into a (postgres) table where the first col is a static value and the second col is the result of a SELECT DISTINCT from another table
I haven't had to use SQL in years and I'm clearly rusty. I have a situation where I'm trying to insert multiple rows into table A. There are two columns of data to be inserted, the first is a "...