Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>insert into table2 values('1,2,3'); </code></pre> <p>most likely needs to be</p> <pre><code>insert into table2 values('1'); insert into table2 values('2'); insert into table2 values('3'); </code></pre> <p>Then, your sub select <code>select field2 from table2</code> returns <code>('1', '2', '3')</code>, and the <code>IN</code> operator can be used to check if the result of the corresponding field from the main select is contained in this set.</p> <hr> <p>According to the comments, the same schema seems to have worked before. I am not aware that the <code>IN</code> operator can be used like in the question, and splitting of column values into a row set seems to be non-trivial. </p> <p>Using the <code>FIND_IN_SET()</code> function as proposed by @KaeL, the following query should work:</p> <pre><code>SELECT b.* FROM table2 a INNER JOIN table1 b ON FIND_IN_SET(b.field1, a.field2) &gt; 0; </code></pre> <p>See also</p> <ul> <li><a href="https://stackoverflow.com/questions/11463090/single-mysql-field-with-comma-separated-values">Single MySQL field with comma separated values</a></li> <li><a href="http://sqlfiddle.com/#!2/795f8/10" rel="nofollow noreferrer">Sample query on SQLFiddle</a></li> </ul> <hr> <p>In any case, you should consider normalizing your schema - using string lists as values of single fields can usually be much better handled by a relational database when the separate values are stored in separate rows in a separate table.</p> <p><a href="http://sqlfiddle.com/#!2/797cc/3" rel="nofollow noreferrer">http://sqlfiddle.com/#!2/797cc/3</a> shows a possible solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload