Need help in SQL and Sequel involving inner join and where/filter
- by mhd
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