Questions tagged [unique]

Refers to an element that is distinctly different from any other element in a collection.

Refers to an element that is distinctly different from any other element in a collection.

6072 questions
112
votes
5 answers

How to create a unique index on a NULL column?

I am using SQL Server 2005. I want to constrain the values in a column to be unique, while allowing NULLS. My current solution involves a unique index on a view like so: CREATE VIEW vw_unq WITH SCHEMABINDING AS SELECT Column1 FROM…
Nuno G
  • 2,035
  • 3
  • 14
  • 16
111
votes
17 answers

How to get an array of unique values from an array containing duplicates in JavaScript?

Given a ['0','1','1','2','3','3','3'] array, the result should be ['0','1','2','3'].
NaveenDAlmeida
  • 1,251
  • 2
  • 10
  • 11
107
votes
11 answers

Merge two numerically-keyed associative arrays and preserve the original keys

I have two arrays like this: array( '11' => '11', '22' => '22', '33' => '33', '44' => '44' ); array( '44' => '44', '55' => '55', '66' => '66', '77' => '77' ); I want to combine these two array such that it does not contains duplicate and as well…
Awan
  • 18,096
  • 36
  • 89
  • 131
104
votes
3 answers

How can I do SELECT UNIQUE with LINQ?

I have a list like this: Red Red Brown Yellow Green Green Brown Red Orange I am trying to do a SELECT UNIQUE with LINQ, i.e. I want Red Brown Yellow Green Orange var uniqueColors = from dbo in database.MainTable where…
baron
  • 11,011
  • 20
  • 54
  • 88
101
votes
4 answers

Unique on a dataframe with only selected columns

I have a dataframe with >100 columns, and I would to find the unique rows by comparing only two of the columns. I'm hoping this is an easy one, but I can't get it to work with unique or duplicated myself. In the below, I would like to unique only…
Ina
  • 4,400
  • 6
  • 30
  • 44
101
votes
6 answers

unique() for more than one variable

I have the following data frame in R: > str(df) 'data.frame': 545227 obs. of 15 variables: $ ykod : int 93 93 93 93 93 93 93 93 93 93 ... $ yad : Factor w/ 42 levels "BAKUGAN","BARBIE",..: 30 30 30 30 30 30 30 30 30 30 ... $ per : Factor w/…
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
92
votes
7 answers

Uniqueness for list of lists

I am curious what would be an efficient way of uniquifying such data objects: testdata =[ ['9034968', 'ETH'], ['14160113', 'ETH'], ['9034968', 'ETH'], ['11111', 'NOT'], ['9555269', 'NOT'], ['15724032', 'ETH'], ['15481740', 'ETH'], ['15481757',…
Hellnar
  • 62,315
  • 79
  • 204
  • 279
91
votes
8 answers

Rails: how can I get unique values from column

How can I get unique values from column in the table? For example, I have this Products table: ID NAME CATEGORY 1 name1 1st_cat 2 name2 2nd_cat 3 name3 1st_cat Here I want to get only 2 values - 1st_cat and 2nd_cat: <%Products.each do…
Oleg Pasko
  • 2,831
  • 5
  • 35
  • 44
90
votes
11 answers

Determining duplicate values in an array

Suppose I have an array a = np.array([1, 2, 1, 3, 3, 3, 0]) How can I (efficiently, Pythonically) find which elements of a are duplicates (i.e., non-unique values)? In this case the result would be array([1, 3, 3]) or possibly array([1, 3]) if…
ecatmur
  • 152,476
  • 27
  • 293
  • 366
87
votes
5 answers

What is the cleanest way to do a sort plus uniq on a Python list?

Consider a Python list my_list containing ['foo', 'foo', 'bar']. What is the most Pythonic way to uniquify and sort a list ? (think cat my_list | sort | uniq) This is how I currently do it and while it works I'm sure there are better ways to do…
knorv
  • 49,059
  • 74
  • 210
  • 294
86
votes
3 answers

Add count of unique / distinct values by group to the original data

I wish to count the number of unique values by grouping of a second variable, and then add the count to the existing data.frame as a new column. For example, if the existing data frame looks like this: color type 1 black chair 2 black chair 3…
Bryan
  • 1,771
  • 4
  • 17
  • 30
86
votes
10 answers

Plot multiple lines (data series) each with unique color in R

I am fairly new to R and I have the following queries : I am trying to generate a plot in R which has multiple lines (data series). Each of these lines is a category and I want it to have a unique color. Currently my code is setup in this way…
user1418321
  • 1,191
  • 2
  • 9
  • 6
84
votes
6 answers

How to sort and remove duplicates from Python list?

Given a list of strings, I want to sort it alphabetically and remove duplicates. I know I can do this: from sets import Set [...] myHash = Set(myList) but I don't know how to retrieve the list members from the hash in alphabetical order. I'm not…
Josh Glover
  • 25,142
  • 27
  • 92
  • 129
82
votes
8 answers

CQRS Event Sourcing: Validate UserName uniqueness

Let's take a simple "Account Registration" example, here is the flow: User visit the website Click the "Register" button and fill out the form, click the "Save" button MVC Controller: Validate UserName uniqueness by reading from…
Mouhong Lin
  • 4,402
  • 4
  • 33
  • 48
81
votes
4 answers

Can I use VARCHAR as the PRIMARY KEY?

I have a table for storing coupons/discounts, and I want to use the coupon_code column as the primary key, which is a VARCHAR. My rationale is that, each coupon will have a unique code, and the only commands I will be running are SELECT ... FROM ...…
Mike Brady
  • 843
  • 1
  • 6
  • 6