Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 joining two tables

Author  Topic 

eem_2055
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 03:26:55
Hi guys,

Good day!

I need your help!

I want to get an accurate data.

Thi is a the sample table.

table 1
------------------
uniqueid acctno name balance
1 0201 sam 102.00
2 0202 mel and geo 105.00
3 0202 mel and geo 105.00

table 2
--------------
uniqueid name
1 sam
2 mel
3 geo

table 3
---------------
uniqueid acctno
1 201
2 202

table 4
------------
acctno interestdate
201 10/15/02

***what can I do to get the following result? How can I join those tables. Hope u can help me! Thanks..

uniqueid acctno name balance interestdate
1 201 sam 102.00 10/15/02
2 202 mel and geo 105.00

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-07 : 03:32:01
[code]Select
t1.uniqueid, t1.acctno, t1.name, t1.balance, t2.interestdate
from Table1 t1 left join table4 t2
on t1.acctno = t2.acctno[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

eem_2055
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 04:00:22
I was wrong! :(

This is the correct sample table.

table 1
------------------
acctno name balance
0201 sam 102.00
0202 mel and geo 105.00
0202 mel and geo 105.00

table 2
--------------
uniqueid name
1 sam
2 mel
3 geo

table 3
---------------
uniqueid acctno
1 201
2 202

table 4
------------
acctno interestdate
201 10/15/02

***what can I do to get the following result? How can I join those tables. Hope u can help me! Thanks..

uniqueid acctno name balance interestdate
1 201 sam 102.00 10/15/02
2 202 mel and geo 105.00
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-07 : 04:35:46
[code]
select t3.uniqueid, t3.acctno, t1.name, t1.balance, t4.interestdate
from table3 t3
inner join table1 t1 on t3.acctno = t1.acctno and t3.uniqueid = t1.uniqueid
left join table4 on t3.acctno = t4.acctno
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -