SQL query. Joins


Place value of a table2 in a query to table1.

I have a query in SQL

SELECT   ROW_NUMBER() over (partition by IdCertificado order by FechaCambio) Consecutivo,
upper (IdCertificado) IdCertificado , IdTipoSolicitud ,
cast (FechaCambio AS date) FechaCambio,
Observaciones , NumFolio, IdEmpleado  from Tabla1 with(nolock)

and throws this at me


I have a table2 which contains this

How can I make the RequestDescription instead of throwing the IDTypeApplication?

Thank you.

asked by ernesdin 31.07.2018 в 21:50

1 answer


You must use Joins , which allows you to combine records from one or more tables, you can try a INNER JOIN

SELECT column_name(s)
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;

For your query you should also add alias , staying more or less like this:

SELECT   ROW_NUMBER() over (partition by a.IdCertificado order by a.FechaCambio) Consecutivo,
upper (a.IdCertificado) IdCertificado , a.IdTipoSolicitud ,
cast (a.FechaCambio AS date) FechaCambio,
a.Observaciones , a.NumFolio, a.IdEmpleado, b.DescripcionSolicitud as Solicitud
   FROM Tabla1 as a
       INNER JOIN tabla2 as b ON a.IdTipoSolicitud = b.IdTipoSolicitud
answered by 31.07.2018 в 22:03