Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql sorting by checkbox array data
    primarykey
    data
    text
    <hr> <p>Hello all, I have a quick problem with mysql query.</p> <p>I'm trying to do a selection and I'm not sure it can be done - or if I'm doing it right.</p> <p>I have a table with a field called ListeningMethod, which contains values from a comma separated array values, inserted from html check boxes. There are 5 possible entries and the field can have all, or none of the checkbox values in it.</p> <p>The sample data would be similar to this:</p> <pre><code>NOLISTEN,RADIO,INTERNET,SATELLITE,MOBILE </code></pre> <p>What I'd like to do is sort the data, but do it by counts. So, if there are 10 appearances of "RADIO", 5 of "MOBILE" and 3 of "SATELLITE" spaced over 10 records, then searching through 100 records, it should be able to show and sort those mentioned results, with the "order by" set to the most common listeningmethod at the top.</p> <p>I tried giving it a go, but didn't go too well.</p> <p>Any thoughts? Thanks.</p> <pre><code>SELECT ListeningMethod, ListeningMethod REGEXP ("NOLISTEN") as ViewNOLISTEN, ListeningMethod REGEXP ("RADIO") as ViewRADIO, ListeningMethod REGEXP ("INTERNET") as ViewINTERNET, ListeningMethod REGEXP ("SATELLITE") as ViewSATELLITE, ListeningMethod REGEXP ("MOBILE") as ViewMOBILE FROM VAT </code></pre> <p>I tried adding more, such as "COUNT(ViewRadio) CountRadio", but it says that column doesn't exist, so I'm a little lost.</p> <p>Example Insert statement:</p> <pre><code>INSERT INTO `VAT` (`ListeningMethod`) VALUES ('NOLISTEN,RADIO,INTERNET,MOBILE'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('INTERNET'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('NOLISTEN'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('INTERNET'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('INTERNET'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('RADIO'); INSERT INTO `VAT` (`ListeningMethod`) VALUES ('MOBILE'); &gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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