SOLVED

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

Copper Contributor

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

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

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

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

# Re: Insert in a field a sequential number for each row in two tables

Try

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

# Re: Insert in a field a sequential number for each row in two tables

@LMontani
Thanks
1 best response

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

# Re: Insert in a field a sequential number for each row in two tables

Try

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