By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,161 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,161 IT Pros & Developers. It's quick & easy.

Urget.. problem in SQL Query

P: n/a
Hi,

I have created 2 tables tbl1 and tbl2 and added data as follows
tbl1:

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc3 333 name3 add3 ty02
acc4 444 name4 add4 ty01
acc5 555 name5 add5 ty02

tbl2:

account_desc accountno
acc1 111
acc2 222
acc3 333
acc4 444
acc5 555

and trying to execute the right outer jon query

select a.* FROM tbl1 a right outer join tbl2 b on a.account_desc =
b.account_desc where a.account_type='TY01'

It is displayed the values

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc4 444 name4 add4 ty01

But, In my application, I want out put similar to the below

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc3
acc4 444 name4 add4 ty01
acc5

Please help me how can we achieve the above result from the SQL
statement.

Regards.
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Omavlana wrote:
Hi,

I have created 2 tables tbl1 and tbl2 and added data as follows
tbl1:

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc3 333 name3 add3 ty02
acc4 444 name4 add4 ty01
acc5 555 name5 add5 ty02

tbl2:

account_desc accountno
acc1 111
acc2 222
acc3 333
acc4 444
acc5 555
Why do you have an second table with the Account Desc and Number
repeated?
and trying to execute the right outer jon query

select a.* FROM tbl1 a right outer join tbl2 b on a.account_desc =
b.account_desc where a.account_type='TY01'

It is displayed the values

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc4 444 name4 add4 ty01

But, In my application, I want out put similar to the below

account_desc accountno acc_name acc_address account_type
acc1 111 name1 add1 ty01
acc2 222 name2 add2 ty01
acc3
acc4 444 name4 add4 ty01
acc5

Please help me how can we achieve the above result from the SQL
statement.

Regards.


Sounds like you need a left outer join instead of right?
--
regards,

Bradley
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.