views:

55

answers:

4

First of all I am using Oracle 10g Express

So there are three columns I want to select:

[domain_name] [index_path] [collection_name]

Now there are two columns that I want to be unique:

[domain_name] [index_path]

So my issue is how do I basically:

select unique domain_name, index_path from TABLENAMEHERE

while also selecting the column [collection_name]

A: 

Just replace unique with distinct in your query.

Oh...

Then it should be like this:

select [domain_name], [index_path], min([collection_name]) 
from TABLENAMEHERE
group by [domain_name], [index_path]
Denis Valeev
A: 

You can group by the domain_name and index_path and include ONE (min or max) value of collection_name per group.

Mike Forman
Yep, this is exactly what I want to do, how does one do that?
Jacob Nelson
+3  A: 

If there are multiple rows for some combinations of domain_name, index_path then what value of collection_name would you want to see from those rows? If you don't mind which value then do:

SELECT domain_name, index_path, MIN(collection_name) collection_name
FROM TABLENAMEHERE
GROUP BY domain_name, index_path;
dportas
What if I was to say there is another column named [gen_timestamp] it is indeed a time stamp and I want to select the row that has the most recent time stamp.
Jacob Nelson
@jacobnlsn: In that case it's kind of unfortunate you didn't metion the requirement in your original post. Maybe you could edit it to explain your full requirements.
dportas
see my answer below - analytics!
Adam Musch
+1  A: 
select domain_name, index_path, collection_name
  from my_table outr
       inner join 
         (select domain_name, index_path, collection_name, 
                 max(gen_timestamp) 
                    over (partition by domain_name, index_path) gen_timestamp
            from my_table) innr
 where outr.domain_name = innr.domain_name
   and outr.index_path  = innr.index_path
   and outr.collection_name = innr.collection_name
   and outr.gen_timestamp   = innr.gen_timestamp
Adam Musch
Looks good, logically speaking it should work, but after (and before) I switch out "my_table" with my actual table name. I get this error: ORA-00905: missing keyword00905. 00000 - "missing keyword"*Cause: *Action:Error at Line: 8 Column: 1
Jacob Nelson