August 31, 2007 at 4:07 am
Hi Experts,
I have faced one question in an interview.
I have two tables called A and B. Table A has 5 records and Table B has 2 records.
I want all the records from Table A and any one record from Table B.
for example,
Table A Table B
1 50
2 100
3
4
5
Output should be
1
2
3
4
5
50
(or)
1
2
3
4
5
100
Anybody help me to get this output.
Regards
Karthik
karthik
August 31, 2007 at 4:32 am
create
table #temp(id int)
create
table #temp1(id int)
insert
into #temp values (1)
insert
into #temp values (2)
insert
into #temp values (3)
insert
into #temp values (4)
insert
into #temp values (5)
insert
into #temp1 values (50)
insert
into #temp1 values (100)
select
id from #temp
union
all
select
min(id) from #temp1
select
id from #temp
union
all
select
max(id) from #temp1
drop
table #temp
drop
table #temp1
if your record is fix then this one is simple logic tha you
can apply
From Yash Barot
August 31, 2007 at 7:43 am
Strange question, but I'd go with the union as well.
August 31, 2007 at 7:53 am
Agree with Steve.
SELECT * FROM TABALEA UNION SELECT TOP 1 * FROM TABLEB
Does it work?
August 31, 2007 at 8:31 am
Thanks Experts !
Regards
Karthik
karthik
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply