Warley Ferreira Dias
Warley Ferreira Dias

Reputation: 19

Two fields from the same table

I have a table with auditors name and another one with the senior auditors that will evaluate auditors.

auditors ( id, name )
1, ademir
2, luana
3, ana

evaluations ( id, idevaluator, idevaluated )
1, 1, 2
2, 1, 3

Ademir will evaluate luana and ana.

So I have to list:
Ademir "will evaluate" luana
Ademir "will evaluate" ana

and I could not create a select that show me that.

If someone knows how to do it, I would appreciate the answer.

Upvotes: 2

Views: 44

Answers (2)

Jens
Jens

Reputation: 69440

You have to join the table Auditors twice with the use of aliasses

select t1.name, t2.name 
from Auditors t1 
join Evaluations on t1.id = idevaluator 
join Auditors t2 on t2.id = idevaluated

Upvotes: 2

D Stanley
D Stanley

Reputation: 152556

Just JOIN the auditors table twice:

SELECT * 
FROM auditors a1
INNER JOIN evaluations e
  ON a1.id = e.idevaluator
INNER JOIN auditors a2
  ON e.idevaluated = a2.id

Upvotes: 2

Related Questions