Need help in SQL and Sequel involving inner join and where/filter

Posted by mhd on Stack Overflow See other posts from Stack Overflow or by mhd
Published on 2010-12-21T14:11:31Z Indexed on 2010/12/22 7:54 UTC
Read the original article Hit count: 260

Filed under:
|
|

Need help transfer sql to sequel:
SQL:

SELECT table_t.curr_id FROM table_t
INNER JOIN table_c ON table_c.curr_id = table_t.curr_id 
INNER JOIN table_b ON table_b.bic = table_t.bic
WHERE table_c.alpha_id = 'XXX' AND table_b.name='Foo';

I'm stuck in the sequel, I don't know how to filter, so far like this:

 cid= table_t.select(:curr_id).
                    join(:table_c, :curr_id=>:curr_id).
                    join(:table_b, :bic=>:bic).
                    filter( ????? )  

Answer with better idiom than above is appreciated as well.Tnx.

UPDATE:
I have to modify a little to make it works

cid = DB[:table_t].select(:table_t__curr_id).
  join(:table_c, :curr_id=>:curr_id).
  join(:table_b, :bic=>:table_t__bic). #add table_t or else ERROR: column table_c.bic does not exist
  filter(:table_c__alpha_id => 'XXX',
         :table_b__name => 'Foo')

without filter,

cid = DB[:table_t].select(:table_t__curr_id).
                    join(:table_c, :curr_id=>:curr_id, :alpha_id=>'XXX').
                    join(:table_b, :bic=>:table_t__bic, :name=>'Foo')

btw I use pgsql 9.0

© Stack Overflow or respective owner

Related posts about sql

Related posts about ruby