Skip to content
Advertisement

SQL: Getting previous record from other table

I want to get the previous record of each record in Table A from Table B.

enter image description here

for easy, below is the table sample data:

EDIT: It should include only last previous record from TableB. Sorry for the confusion. Changed image and sample data also.

Advertisement

Answer

I think you want:

Here is a db<>fiddle.

EDIT:

If b could have multiple “previous” records, then:

Here is a db<>fiddle for this version.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement