[thelist] MySQL multiple counts problem
jft
jft at worrigee.net
Fri Feb 13 06:37:47 CST 2009
Cristian,
If what you are after is a single row output with two columns, one for the number of breakfast available motels & the other for the number of conference available motels, try this:
SELECT (SELECT count(*) FROM motels where breakfast_available = 1) 'Breakfast',(SELECT count(*) FROM motels where conference_facilities = 1) 'Conference' from motels limit 1;
A minor variation would be:
SELECT (SELECT count(*) FROM motels where breakfast_available = 1) 'Breakfast',(SELECT count(*) FROM motels where conference_facilities = 1) 'Conference' from dual;
HTH,
John
> -------Original Message-------
> From: Cristian Rosescu <crosescu at gmail.com>
> Subject: [thelist] MySQL multiple counts problem
> Sent: 13 Feb '09 16:14
> I have a MySql database that contains a 'motels' table. One of the fields in
> the table is 'breakfast_available' and this contains an integer (1 for yes,
> 0 for no). The other field in this table is 'conference_facilities' which
> also stores an integer value 1 or 0
> I would like to setup one MySql query that will display this number of
> motels have breakfast available (breakfast_available = 1) and this number of
> motels provide conference facilities (conference_facilities = 1)
> --
More information about the thelist
mailing list