Forum Moderators: phranque
Table Business, ID is the primary key, and there are various combination of different cuisines/suburbs in each row.
Thanks.
I don't think you are going to be able to combine your statements. DISTINCT means exactly that. Consider the example snippet of a table in your database:
+---------+--------+
¦ cuisine ¦ suburb ¦
+---------+--------+
¦ chinese ¦ subone ¦
¦ chinese ¦ subtwo ¦
¦ chinese ¦ subsix ¦
¦ italian ¦ subone ¦
¦ italian ¦ subtwo ¦
+---------+--------+
If you
SELECT DISTINCT cuisine FROM table
SELECT DISTINCT suburb FROM table
If you
SELECT DISTINCT cuisine, suburb FROM table
Also, I'm wondering if the data is at all normalized. Can you have:
+---------+--------+---+
¦ cuisine ¦ suburb ¦ID ¦
+---------+--------+---+
¦ chinese ¦ subone ¦ 1 ¦
¦ italian ¦ subone ¦ 1 ¦
¦ chinese ¦ subtwo ¦ 2 ¦
+---------+--------+---+
If so, it's going to be hairy!
The data is normalised w auto-incrementing id fields.
Danieljean, the aim of the query was to get the data required to fill in a 'summary of results'.
eg: Your search found:
Chinese (3)
Italian (2)
subone (2)
subtwo (2)
subsix (1) (see coopster's table data)
as in ignoring the relations between cuisine and suburb, simply returning the basic count of each distinct value.
Logically, it makes sense to run separate queries - but wanted to minimise no. queries I am running.
Thanks.
(Did I ever mention here on WW that I dislike MySQL?)
Anyhow, keep in mind that "premature optimization is the root of all evil", and try first doing the multiple, simple queries. For all its faults, MySQL is at least fast :)