Hi everyone,
SELECT *
FROM `jobs`
WHERE (SELECT DISTINCT jobs.*
FROM jobs, job_requests
WHERE (jobs.user_id = 1) OR
(job_requests.user_id = 1 AND job_requests.job_id = jobs.id)
)
This sql gives me:
Mysql::Error: Operand should contain 1 column(s).
If I execute the select from the where clause it works
SELECT DISTINCT jobs.* FROM jobs, job_requests
WHERE (jobs.user_id = 1) OR
(job_requests.user_id = 1 AND job_requests.job_id = jobs.id)
Could somebody explain me why? This query is generated by rails activerecord so the main select is needed.
The ror code:
has_many :my_jobs, :class_name=>"Job", :finder_sql =>
'SELECT DISTINCT jobs.* ' +
'FROM jobs, job_requests ' +
'WHERE (jobs.user_id = #{id}) OR ' +
'(job_requests.user_id = #{id} AND job_requests.job_id = jobs.id AND job_requests.request_status IN ("requested", "confirmed") )'