How to group the result of a query

0

I need to relate two tables with INNER JOIN .

In a relationship table I have Estudiante

In the table students I have Estudiante , Nombre , Grado .

I need to relate both tables in a query and the result is one.

The query I have.

SELECT DISTINCT t.Id_Estudiante, u.Id_Estudiante, Nombres, Grado FROM relacion INNER JOIN estudiantes WHERE relacion.r = estudiantes.u

The end of what I want is for you to show me the Id_Estudiante , the name of the student and the grade you are studying.

The Estudiante field is the initials of the student's name. Example:

María Alejandra Ortiz = maortiz
    
asked by FOX 20.09.2017 в 16:25
source

2 answers

1

I think I understand by saying that

  

I need to relate both tables in a query and that the result    be one .

What you want is that the results are not repeated, if so, you have 2 options.

DISTINCT

select distinct(r.Id_Estudiante), e.Nombres, e.grado
from relacion r
inner join estudiantes e on e.Id_Estudiante = r.Id_Estudiante

GROUP BY

select r.Id_Estudiante, e.Nombres, e.grado
from relacion r
inner join estudiantes e on e.Id_Estudiante = r.Id_Estudiante
group by r.Id_Estudiante
    
answered by 20.09.2017 / 16:46
source
1

Review the SQL documentation. What you should do is indicate the relationship fields in the INNER JOIN clause with the format INNER JOIN [tabla] ON [campo_tabla1]=[campo_tabla2]

Basically:

SELECT relacion.Id_Estudiante, estudiantes.Nombre, estudiantes.Grado
FROM relacion
INNER JOIN estudiantes ON estudiantes.Id_Estudiante=relacion.Id_estudiante
    
answered by 20.09.2017 в 16:30