SOLVED

Insert in a field a sequential number for each row in two tables

Copper Contributor

Good morning, I am new to this topic, please help me with the following. Thank you very much

 

With ROW_NUMBER() OVER I am trying to insert in a field a sequential number for each row of two tables. This works for me if I apply it for all rows of a single table. How can I do it for two or more joined tables? Or what other function or technique can I use?

This is the sentence

SELECT

ROW_NUMBER() OVER(ORDER BY IC.IDP ASC) [Consecutivo]

,IC.IDP [Id del P]

,IC.FECHA [Fecha en tabla IC]

,IM.FECHA [Fecha en tabla IM]

 

FROM TABLA_IC IC

inner join TABLA_IM IM ON IM.IDPM = IC.IDP

where IC.IDP = 106

 

Which only brings me the records of TABLA_IC

wcastro_0-1643040571946.png

But I want to get the records from both tables TABLA_IC and TABLA_IM. So

wcastro_1-1643040616606.png

 

 

 

 

 

 

2 Replies
best response confirmed by wcastro (Copper Contributor)
Solution
Try

FROM TABLA_IM IM
left join TABLA_IC IC ON IM.IDPM = IC.IDP
where IC.IDP = 106
1 best response

Accepted Solutions
best response confirmed by wcastro (Copper Contributor)
Solution
Try

FROM TABLA_IM IM
left join TABLA_IC IC ON IM.IDPM = IC.IDP
where IC.IDP = 106

View solution in original post