Home » SQL & PL/SQL » SQL & PL/SQL » Left outer Join nt working as desired (Oracle 11g)
Left outer Join nt working as desired [message #615547] Thu, 05 June 2014 05:44 Go to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
Hi ,

I am using one query and not getting the correct result. Table int_indices has 6000 unique records.Table int_index_currency_det has 10000 records. I want to make a left outer join between int_indices and int_index_currency_det such that all the records with same index id and vendor_id gets picked up. So finally my result set should contain 6000 records. Here the b.status_in = 'A' is not working as desired. In the result set getting inactive reords as well. Please help.

select b.*, bc.Currency_id
from int_indices b
left join
int_index_currency_det bc
on b.index_id = bc.index_id
and b.vendor_id = bc.vendor_id
and b.current_rec_in = Y
and bc.current_rec_in = Y
and b.status_in = 'A'
and bc.status_in = 'A'
and bc.currency_type_id = 'PRIMARY'
Re: Left outer Join nt working as desired [message #615550 is a reply to message #615547] Thu, 05 June 2014 05:59 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Please read and follow How to use [code] tags and make your code easier to read?

If you only want records from int_indices where status_in = 'A' then that should be specified in the where clause, not the join clause.
Re: Left outer Join nt working as desired [message #615552 is a reply to message #615550] Thu, 05 June 2014 06:14 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
Sir,

Even after putting that way am not getting the appropriate records count.

SELECT b.*,
       bc.currency_id
FROM   int_indices b
       left join int_index_currency_det bc
              ON b.index_id = bc.index_id
                 AND b.vendor_id = bc.vendor_id
                 AND bc.currency_type_id = 'PRIMARY'
WHERE  b.current_rec_in = 'Y'
       AND bc.current_rec_in = 'Y'
       AND b.status_in = 'A'
       AND bc.status_in = 'A' 

[Updated on: Thu, 05 June 2014 06:15]

Report message to a moderator

Re: Left outer Join nt working as desired [message #615556 is a reply to message #615552] Thu, 05 June 2014 06:40 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Please post the table create statements and insert statements with some sample values. And also post the desired output.
Re: Left outer Join nt working as desired [message #615558 is a reply to message #615556] Thu, 05 June 2014 06:48 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
I cannot post the table structure and data as those will be a data security breach. Kindly let me know incase you find something wrong in the above query.

[Updated on: Thu, 05 June 2014 06:48]

Report message to a moderator

Re: Left outer Join nt working as desired [message #615559 is a reply to message #615558] Thu, 05 June 2014 06:51 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
You have the filter predicate AND bc.currency_type_id = 'PRIMARY' in the join clause instead of where clause.
Re: Left outer Join nt working as desired [message #615594 is a reply to message #615559] Thu, 05 June 2014 13:45 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Lalit Kumar B wrote on Thu, 05 June 2014 12:51
You have the filter predicate AND bc.currency_type_id = 'PRIMARY' in the join clause instead of where clause.


That's probably in the correct place. If you move it to the where clause it'll render the outer-join pointless since 'PRIMARY' != null (made up by outer join).

@raj_te - all restrictions against int_index_currency_det should probably be in the join clause and all restrictions against int_indices should be in the where clause.

If that doesn't give what you want then you're going to have to actually describe the relationship between the two tables to us. It's very difficult to guess what code you know nothing about, and doesn't work, is supposed to do.
Previous Topic: Insert with different key values to avoid contraint violation
Next Topic: SQL QUERY
Goto Forum:
  


Current Time: Fri Apr 19 05:21:57 CDT 2024