Rob Biedenharn wrote:
> On May 14, 2009, at 5:34 AM, Venkat Eee wrote:
>> Please,
>>
>> Can anyone help me to execute this query?
>>
>> SELECT * FROM table WHERE customer_id IN (SELECT IF(1 <> 2,'SELECT
>> customer_id FROM customers','SELECT customer_id FROM company'))
>>
>> Regards...
>> --  
> 
> 
> No!
> 
> It looks like you're trying to do either:
> 
> SELECT table.* FROM table INNER JOIN customers ON
> customers.customer_id = table.customer_id
> 
> or:
> 
> SELECT table.* FROM table INNER JOIN company ON company.customer_id =
> table.customer_id
> 
> So you can do either of those (after you substitute for 'table' of
> course)
> 
> If this is Rails (ActiveRecord), then ask your question again with
> some more background and perhaps a bit of code (not SQL) and you'll
> get a better answer.  (And that answer will probably show you how to
> use has_many and belongs_to associations in your models.)
> 
> -Rob
> 
> Rob Biedenharn    http://agileconsultingllc.com
> [email protected]




Thanks... Rob Biedenharn

I got the solution for that...below code is working fine for me... :-)


SELECT * FROM books WHERE customer_id IN  (SELECT customer_id FROM 
customers WHERE (IF('#{user_type}' <> 2,customer_id IS NOT 
NULL,company_id='"cus01"')))

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to