How to make INNER JOIN between a table in SQL SERVER and a linked server?

0

Well I mean, I have a database in SQL SERVER called SIELAB and another database in PostgreSQL called reservations , I managed to make the connection correctly and I have already managed to execute a SELECT query from a stored procedure in SQL SERVER to a table I have in PostgreSQL . I did the consultation in the following way:

SELECT * 
FROM OPENQUERY(MYLINKEDSERVER,
'SELECT usu_id_pk AS Id_usuario, usu_nombre_completo AS Nombre_usuario FROM reservas.usuario')

Now in my bd of SQL SERVER I have a table that has a usu_id_pk field as in the bd table of the PostgreSQL server, I need to make an INNER JOIN between these two tables in order to bring the data I need from the table in POSTGRESQL .

I hope you can help me, thanks!

    
asked by JDiego9708 17.08.2017 в 04:20
source

1 answer

0

Try to join using the linked server. It could be something like this:

SELECT
    t1.campo1
    ,...
FROM
    [BaseDatosLocal].[esquema1].[TablaLocal] t1
    INNER JOIN [LinkedServer].[BaseDatosRemota].[esquema2].[TablaRemota] t2 
ON
    t1.Id = t2.Id

It may not be necessary to include schema2.

I hope it works.

    
answered by 17.08.2017 / 23:43
source