unique
SQL – select distinct only on one column [duplicate]
A very typical approach to this type of problem is to use row_number(): select t.* from (select t.*, row_number() over (partition by number order by id) as seqnum from t ) t where seqnum = 1; This is more generalizable than using a comparison to the minimum id. For instance, you can get a random … Read more
Composite PRIMARY KEY enforces NOT NULL constraints on involved columns
If you need to allow NULL values, use a UNIQUE constraint (or index) instead of a PRIMARY KEY (and add a surrogate PK column – I suggest a serial or IDENTITY column in Postgres 10 or later). Auto increment table column A UNIQUE constraint allows columns to be NULL: CREATE TABLE distributor ( distributor_id GENERATED … Read more
Removing duplicate objects (based on multiple keys) from array
Late one, but I don’t know why nobody suggests something much simpler: listOfTags.filter((tag, index, array) => array.findIndex(t => t.color == tag.color && t.label == tag.label) == index);
Delete all but one duplicate record
ANSI SQL Solution Use group by in a subquery: delete from my_tab where id not in (select min(id) from my_tab group by profile_id, visitor_id); You need some kind of unique identifier(here, I’m using id). MySQL Solution As pointed out by @JamesPoulson, this causes a syntax error in MySQL; the correct solution is (as shown in … Read more
Getting first n unique elements from Python list
I would use a set to remember what was seen and return from the generator when you have seen enough: a = [1, 2, 2, 3, 3, 4, 5, 6] def get_unique_N(iterable, N): “””Yields (in order) the first N unique elements of iterable. Might yield less if data too short.””” seen = set() for e … Read more
#1062 – Duplicate entry ” for key ‘unique_id’ When Trying to add UNIQUE KEY (MySQL)
The error says it all: Duplicate entry ” So run the following query: SELECT unique_id,COUNT(unique_id) FROM yourtblname GROUP BY unique_id HAVING COUNT(unique_id) >1 This query will also show you the problem SELECT * FROM yourtblname WHERE unique_id=” This will show you where there are values that have duplicates. You are trying to create a unique … Read more
underscore/lodash unique by multiple properties
Use Lodash’s uniqWith method: _.uniqWith(array, [comparator]) This method is like _.uniq except that it accepts comparator which is invoked to compare elements of array. The order of result values is determined by the order they occur in the array. The comparator is invoked with two arguments: (arrVal, othVal). When the comparator returns true, the items … Read more
JavaScript Unique Browser Id
What you are looking for is called Browser Fingerprinting. You can google for some open source libraries. Ex: fingerprintjs2 Check out EFF’s demo
Detecting a “unique” anonymous user
There are actually many ways you can detect a “unique” user. Many of these methods are used by our marketing friends. It get’s even easier when you have plugins enabled such as Java, Flash etc. Currently my favorite presentation of cookie based tracking is evercookie (http://samy.pl/evercookie/). It creates a “permanent” cookie via multiple storage mechanisms, … Read more