cancel
Showing results for 
Search instead for 
Did you mean: 

SELECT DISTINCT SQL for Projects

adamishak12
Explorer
0 Kudos

All, 

This is my current SQL Query:

SELECT "Project","Project Name","Labor Budget","Labor Billed","Address1","period","year","month","Calculated_1" From REA

I want to only bring in the DISTINCT Project's so for example as of now it's showing 

 

ProjectProject NameLabor BilledLabor BudgetAddress1PeriodYearMonth

1

Elmers Ave

171100

2550

460 Madison Ave

201501

2015

1

1

Elmers Ave

171100

3000

460 Madison Ave

201601

2016

1

1

Elmers Ave

171100

3750

460 Madison Ave

201507

2015

7




I would only want to bring in 1 value for each project number. Is this possible?

ProjectProject NameLabor BilledLabor BudgetAddress1PeriodYearMonth

1

Elmers Ave

171100

2550

460 Madison Ave

201501

2015

1

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Johan_H
Active Contributor
0 Kudos

Hi,

DISTINCT will only group everything into one row, when all columns have the exact same value over all rows. In your example data the values in the diffrerent columns are all different, so you cannot use distinct.

You have a few options that you can use alone or in some combination:

  • Add a WHERE clause to get the specific row you want. For example WHERE "Year" = 2015
  • Add an ORDER BY clause, and TOP 1. So something like this: 
    SELECT TOP 1 "Project"...etc
    etc
    ORDER BY "Year"
  • Select less columns, and the COUNT() or SUM() function(s). For Example SELECT "Project", SUM("Labour Budget") AS "Labour Budget" FROM etc.

Regards,

Johan