Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two tables in sql
table1
1
2
3
5
 
table 2
2
3
4
6
 
output
 
2 2 
3 3
4 3
6 5


if matcing value found col should join on matching value else nearest lower value.

Please help me

I want to update lower or similar value in table2,,,It's urgent

Thanks in advance

What I have tried:

I have tried some joins but not succeeded, plz help
Posted
Updated 15-Nov-20 9:35am
v3

1 solution

select t2.*, t1.*
from table2 as t2
join table1 as t1
  on t1.i = (select max(t3.i) from table1 as t3 where t3.i <=t2.i)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900