HELP - From SQL to Ruby

L

luciosan

Hi

How I can execute this query on Ruby?

SELECT *
FROM table_1 T
WHERE T.document_id not in (SELECT distinct documnet_id FROM
binary_files);

Now, I execute without proble the second part of query (SELECT
distinct documnet_id FROM binary_files) in this
method:BinaryFile.find:)first, :select => 'distinct document_id')

I've all crontrollers and all models

Thank you
 
K

khaines

Hi

How I can execute this query on Ruby?

SELECT *
FROM table_1 T
WHERE T.document_id not in (SELECT distinct documnet_id FROM
binary_files);

Now, I execute without proble the second part of query (SELECT
distinct documnet_id FROM binary_files) in this
method:BinaryFile.find:)first, :select => 'distinct document_id')

dbh = DBI.open('dbi:mysql:foo','username','password)
dbh.select_all('SELECT * FROM table_1 T WHERE T.document_id not in (SELECT
distinct documnet_id FROM binary_files)') do |row|
# do stuff with rows
end

or, maybe

ksdbh = KSDatabase.new('dbi:mysql:foo','username','password)
doc_ids = ksdbh.select:)BinaryFiles) do |b|
b.distinct(b.document_id)
end.collect do |d|
d.document_id
end

data = ksdbh.select:)Table1) {|t| t.document_id.not_in(doc_ids)}
I've all crontrollers and all models

My point is that there are many ways to do what you ask in _Ruby_. I
imagine you are actualy wanting to know how to do it in ActiveRecord?


Kirk Haines
 
L

luciosan

My point is that there are many ways to do what you ask in _Ruby_.
I imagine you are actualy wanting to know how to do it in
ActiveRecord?

Thank you for the answare.... yes I'm waiting to know how I can do it
in ActiveRecord.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,269
Messages
2,571,348
Members
48,026
Latest member
ArnulfoCat

Latest Threads

Top