.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

how to display two table records one by one

Posted By: ssk     Posted Date: December 07, 2012    Points:5   Category :Sql Server
Hi Friends,
`
i have two tables.i need to join two table and display records in firstrow from first table and secondrow from second table.

for ex...

table A conatains

ID name
1 AAA
2 BBB
3 CCC

table B contains

ID place
1 ZZZ
2 XXX
3 YYY

i need to display first row from A table and second row from second table.like

1 AAA
1 ZZZ
2 BBB
2 XXX
3 CCC
3 YYY

Responses
Author: Baimey Rajesh             
Posted Date: December 09, 2012     Points: 20   

On what criteria is this merging coming in.

Please specify the situation
Thanks
Baimey

Author: Baimey Rajesh             
Posted Date: December 09, 2012     Points: 20   

If the suituation is similar to
http://stackoverflow.com/questions/5575682/how-to-merge-data-from-multiple-tables-in-sql


Use a join.

select enrollment.*, student.*, course.* from enrollment
inner join Student on enrollment.studentId = student.studentId
inner join Course on enrollment.courseId = course.courseId

Author: Sasi Prabhu             
Posted Date: December 16, 2012     Points: 20   

Use Union.

insert #temp
select ID,name from tableA
union
select ID,place from tableB

select * from #temp order by ID


Thanks & Regards,
Sasi Prabhu.
Author: Petr Matejovsky             
Posted Date: December 30, 2012     Points: 20   

Hi,

try this:

SELECT ID, Name
FROM A
UNION ALL
SELECT ID, Place
FROM B
ORDER BY ID;


Petr




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend