Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
select distinct
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Peter De Keer  
View profile  
 More options Jun 2 2009, 12:56 pm
From: Peter De Keer <peter.de.k...@gmail.com>
Date: Tue, 2 Jun 2009 09:56:52 -0700 (PDT)
Local: Tues, Jun 2 2009 12:56 pm
Subject: select distinct
I know I'm asking questions not only needed for dovetail, but how
could I do this?

SQL SELECT DISTINCT function FROM Jobs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pschan...@gmail.com  
View profile  
 More options Jun 3 2009, 9:24 am
From: pschan...@gmail.com
Date: Wed, 3 Jun 2009 06:24:29 -0700 (PDT)
Local: Wed, Jun 3 2009 9:24 am
Subject: Re: select distinct
The plain old javascript way to do it is to set keys on an object:

==== BEGIN JS ====
// supposing <jobs> is an array of objcts:
var functions = {};
for(var i=0; i<jobs.length; i++) {
  functions[jobs[i].function]=1;

}

for (var f in functions) {
  // will iterate only once for each distinct value
}

==== END JS ====

You can also do it server-side with DovetailDB's map/reduce:

==== BEGIN SERVER-SIDE JS ====
function getJobFunction(job) {
  var functions={};
  functions[job.function] = 1;
  return functions;

}

function mergeFunctions(functions1, functions2) {
  for(var k2 in functions2) {
    functions1[k1] = 1;
  }
  return functions1;
}

==== END SERVER-SIDE JS ====

And calling on the client side like so:

==== BEGIN JS ====
dovetail.query('people', {}, {map:'getJobFunction',
reduce:'mergeFunctions'}, function(functions) {
  for(var f in functions) {
    // will iterate only once for each distinct value
  }

});

==== END JS ====

Hope this helps!
  Phil

On Jun 2, 12:56 pm, Peter De Keer <peter.de.k...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »