Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select Rows only have Maximum Rating in Joined table.

$
0
0

Hi All,

   I am currently writing a query in sql server 2008, I have following 3 tables and looking for a following output (mention below), but I cannot work out with query.

Table 1: Employee

Emp_ID

Name

City

1

Paul

Dundee

2

Paul 1

Glasgow

3

Paul 2

Leeds

4

Khan

Manchester

Table 2: Category

Cat_ID

Des

Rating

1

Very Excellent

6

2

Excellent

5

3

Good

4

4

Fair

3

5

Poor

2

6

Very Poor

1

Table 3: EmployeeCategory

EmpCat_ID

Cat_ID

Emp_ID

1

2

1

2

3

1

3

1

2

4

3

2

5

4

4

6

2

3

I am looking for a following output. (i.e. When we select rows it return all rows, but i only want to select Top Row against each employee.)

Emp_ID

Name

City

Des

1

Paul

Dundee

Excellent

2

Paul 1

Glasgow

Good

3

Paul 2

Leeds

Excellent

4

Khan

Manchester

Fair

I have used the following query with Max function and tried different approach, but failed to get the above output.

Select E.EmpID, E.Name, E.City, C.Des

from Employee E, Category C, EmployeeCategory EC

Where E.Emp_ID = EC.Emp_ID

AND C.Cat_ID = EC.Cat_ID

Thanks for your help.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>