Mysql query is not working


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'))



It looks like you're trying to do either:

SELECT table.* FROM table INNER JOIN customers ON customers.customer_id = table.customer_id


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 Biedenharn

Rob Biedenharn wrote: