Hello all, I have a quick problem with mysql query.
I'm trying to do a selection and I'm not sure it can be done - or if I'm doing it right.
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.
The sample data would be similar to this:
NOLISTEN,RADIO,INTERNET,SATELLITE,MOBILE
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.
I tried giving it a go, but didn't go too well.
Any thoughts? Thanks.
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
I tried adding more, such as "COUNT(ViewRadio) CountRadio", but it says that column doesn't exist, so I'm a little lost.
Example Insert statement:
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');
>