Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may not want to store a comma delimited list in a column, but since you are:</p> <pre><code>SELECT userid, name FROM mytable WHERE invitedusers = '(' + '234' + ')' -- One and only one entry OR invitedusers LIKE '(' + '234' + ',%' -- First entry OR invitedusers LIKE '%,' + '234' + ',%' -- Middle entry OR invitedusers LIKE '%,' + '234' + ')%' -- Last entry </code></pre> <p>I have modified based on EBarr's comment. There are four cases to check for. This assumes you are storing the data with a ( prefix and a ) suffix and separating everything with commas.</p> <p>Here are some tests to prove that it works:</p> <pre><code>/* Tests */ INSERT INTO @mytable SELECT 11, 'a', '(234)' -- Should get returned INSERT INTO @mytable SELECT 12, 'b', '(1234)' INSERT INTO @mytable SELECT 13, 'c', '(92349)' INSERT INTO @mytable SELECT 13, 'd', '(2345)' INSERT INTO @mytable SELECT 21, 'a', '(234,567)' -- Should get returned INSERT INTO @mytable SELECT 22, 'b', '(1234,567)' INSERT INTO @mytable SELECT 23, 'c', '(92349,567)' INSERT INTO @mytable SELECT 23, 'd', '(2345,567)' INSERT INTO @mytable SELECT 31, 'a', '(567,234)' -- Should get returned INSERT INTO @mytable SELECT 32, 'b', '(567,1234)' INSERT INTO @mytable SELECT 33, 'c', '(567,92349)' INSERT INTO @mytable SELECT 33, 'd', '(567,2345)' INSERT INTO @mytable SELECT 41, 'a', '(123,234,789)' -- Should get returned INSERT INTO @mytable SELECT 42, 'b', '(123,1234,789)' INSERT INTO @mytable SELECT 43, 'c', '(123,92349,789)' INSERT INTO @mytable SELECT 43, 'd', '(123,2345,789)' SELECT userid, name FROM @mytable WHERE invitedusers = '(' + '234' + ')' -- One and only one entry OR invitedusers LIKE '(' + '234' + ',%' -- First entry OR invitedusers LIKE '%,' + '234' + ',%' -- Middle entry OR invitedusers LIKE '%,' + '234' + ')%' -- Last entry </code></pre>
 

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