views:

414

answers:

2

Hello,

I need an sql statement which will allow me to select an entire row from oracle database, but by distinct columns. Here is a simplified database:

    Project_Num    Title        Category
    0              Project 1    Admin
    0              Project 1    Development
    1              Project 2    Admin
    2              Project 3    Development

I need my statement to return the following result set:

0     Project 1    Admin
1     Project 2    Admin
2     Project 3    Development

So each project is returned based on whether its project_num and title are unique. If a project has 2+ entries where its category is different, I need to only select that project once (it doesn't matter which entry I select for that project).

Can anyone help me please?

+5  A: 
SELECT Project_Num, Title, MIN(Category) AS Category
FROM MyTable
GROUP BY Project_Num, Title;
Bill Karwin
+2  A: 

Do you even need to have the Category column in your result set?

If not then you could just use:

SELECT DISTINCT Project_Num, Title
FROM MyTable
Stephen Mesa