Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql combining two tables.

Status
Not open for further replies.

kingstonr

Programmer
Dec 5, 2005
26
US
HI,

I Have two tables table1 and table2

Table1
--------
id Name
1 Test1

Table 2
--------
id Name
1 Test2

I need the result like below

Table1id Table2id Table1name Table2name
1 2 Test1 Test2

Can anybody help me in this.

Thanks
Kingston
 
Code:
Select Table1.Id,
       Table1.Name As Table1Name,
       Table2.Name As Tablee2Name
From   Table1
       Inner Join Table2
         On Table1.Id = Table2.Id


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
What if you have these values:
[tt]
Table1
--------
id Name
-------------
1 Test1_1
2 Test1_2


Table 2
--------
id Name
---------
1 Test2_1
2 Test2_2
3 Test2_3
4 Test2_3
[/tt]
What result you want?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Thanks George.

Borissov in my case Name is unique.
 
OK, in mine too.
[tt]
Table1
--------
id Name
-------------
1 Test1_1
2 Test1_2


Table 2
--------
id Name
---------
1 Test2_1
2 Test2_2
3 Test2_3
4 Test2_4
[/tt]
There is no duplicated Name in both tables. But I have more records in one table than another. So my question is still here. What you want if you have such data?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top