 <p>You can't use REPLACE to create a comma delimited list for use in an <code>IN</code> clause. To use that as-is, you'd have to utilize <a href="http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html" rel="nofollow noreferrer">MySQL's Prepared Statements</a> (effectively dynamic SQL) - creating the comma separated list first, and inserting that into the SQL query constructed as a string before executing it.</p> <pre><code>SELECT a.category_id, a.yyyymm, a.cat_balance_ytd FROM GL_VIEW_CAT_BALANCES a JOIN GL_OPTIONS o ON INSTR(o.detail2, a.category_id) AND o.option_id = 'GLREPFUNCJOB01' JOIN (SELECT b.category_id, b.gl_unique_id, MAX(b.yyyymm) 'yyyymm' FROM GL_REPCAT_BALSs b WHERE b.yyyymm &lt;= 200910 GROUP BY b.category_id, b.gl_unique_id) x ON x.category_id = a.category_id AND x.gl_unique_id = a.unique_id AND x.yyyymm = a.yyyymm WHERE a.gl_id = '/JOB//9' AND a.fin_years_ago = 0 </code></pre> <p>Here's an untested, possible non-dynamic SQL alternative, using <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set" rel="nofollow noreferrer"><code>FIND_IN_SET</code></a>:</p> <pre><code>SELECT a.category_id, a.yyyymm, a.cat_balance_ytd FROM GL_VIEW_CAT_BALANCES a JOIN (SELECT REPLACE(o.detail_2, ' ', ', ') 'detail2_csv' FROM GL_OPTIONS o WHERE o.option_id = 'GLREPFUNCJOB01') y ON FIND_IN_SET(a.category, y.detail2_csv) &gt; 0 JOIN (SELECT b.category_id, b.gl_unique_id, MAX(b.yyyymm) 'yyyymm' FROM GL_REPCAT_BALSs b WHERE b.yyyymm &lt;= 200910 GROUP BY b.category_id, b.gl_unique_id) x ON x.category_id = a.category_id AND x.gl_unique_id = a.unique_id AND x.yyyymm = a.yyyymm WHERE a.gl_id = '/JOB//9' AND a.fin_years_ago = 0 </code></pre>