15,961,678 members
See more:
Hi,

I have a table table1.

table1 has one column:ID
data are:
ID
1
2
3
4
5
6
7
8
9
10

Another table is present as Table2

has 2 column: ID,Amt

Data are:

ID Amt
1 10
5 20
7 100

Now i need a result as

ID Amt

1 10
2 10
3 10
4 10
5 20
6 20
7 100

PLease tell me query to achive this
Posted

## Solution 3

Very strange data and requirement...
With the data shown above, following query works:
SQL
```SELECT Table1.ID,  Max(Table2.Amt)
FROM Table1, Table2
where table1.id>=table2.id and table1.id<=7
group by table1.id```

The maximum value of table2 need not be hard coded but can be retrieved via a subquery:
SQL
```SELECT Table1.ID,  Max(Table2.Amt)
FROM Table1, Table2
where table1.id>=table2.id and table1.id<= (select max(table2.id) from table2)
group by table1.id```

[/Edit]

v2
Maciej Los 20-Feb-14 15:31pm
It looks perfect!
+5!
King Fisher 20-Feb-14 23:33pm
Good one

## Solution 2

Join Query :
SQL
```SELECT t2.ID, t2.Amt
FROM Table1 t1, Tabele2 t2
WHERE t1.ID = t2.ID```

-KR

praveen.victor 20-Feb-14 8:21am
its not satisfying the requirment
Krunal Rohit 20-Feb-14 8:25am
I have seen such cases where "no repeatation" of data is needed. The result you need is simply depends upon the data but query.
Any way, can you tell me why are you doing this ?
-KR

## Solution 1

SQL
`select a.id,case when a.id between 1 and 4 then 10 when a.id between  5 and 6 then 20 when a.id between 7 and 10 then 100 end  From table1 as a left join table2 as b on a.id=b.id`

v3