Skip to content

How to unique by multiple properties

agershun edited this page Dec 28, 2014 · 1 revision

How to unique by multiple properties?

Source: StackOverflow.com

Question

There is an array of objects with duplicates and I'm trying to get a unique listing, where uniqueness is defined by a subset of the properties of the object. For example,

    {a:"1",b:"1",c:"2"}

And I want to ignore c in the uniqueness comparison.

Answer

    var data = [{a:"1",b:"1",c:"2"},{a:"1",b:"1",c:"1"}];

    var res = alasql('SELECT a,b FROM ? GROUP BY a,b',[data]);

Try this example at jsFiddle

Clone this wiki locally