Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query to retrieve values from a comma separated column
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2647/split-string-in-sql">Split string in SQL</a><br> <a href="https://stackoverflow.com/questions/8679376/searching-a-column-with-comma-seperated-values">Searching a column with comma seperated values</a> </p> </blockquote> <p>In my <strong>PHP</strong> project I'm facing a problem to write a SQL:</p> <p>I have a table "<strong>consultants</strong>" with fields <strong><em>categories</em></strong> which has values like:</p> <pre><code>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + id | consultant_name | categories + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 | AOAOAO | health,insurance,programming, + + 2 | BOBOBO | health,gaming,windows,mobile, + + 3 | CCCCCC | insurance,windows, + + 4 | DDDDDD | mobile, + + . | ...... | ............ + + . | ...... | ............ + + . | ...... | ............ + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ </code></pre> <p>And I have <strong>an array which contains all the categories</strong> that a consultant can register with.</p> <pre><code>$arrayOfCategories = $array("health","insurance","programming", "sports","gaming","windows","apple", "mobile","astrology"); </code></pre> <p>What I want is a <em>SQL Query that should give me an output</em> like:</p> <pre><code>+++++++++++++++++++++++++++++++ + category | occurrence + +++++++++++++++++++++++++++++++ + health | 2 + + insurance | 2 + + programming | 1 + + sports | 0 + + gaming | 1 + + windows | 2 + + apple | 0 + + mobile | 2 + + astrology | 0 + +++++++++++++++++++++++++++++++ </code></pre> <p>Any kind of help will be appreciated...</p> <p>Thanks In Advance...</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.
 

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