I’m pulling information that will eventually be from 5 tables at once based off of a filtering system. Right now I have three different databases running, its looking great. My issue is I have certain fields that I only want to display distinct information on and others i want to display all. To better explain I’m going to give my example.
My select code:
SELECT w.event,
w.city,
w.DATE,
a.TIME,
w.tmc,
a.weather,
a.surface_temperature,
p.top,
p.LEFT
FROM weather w
LEFT OUTER JOIN application a
ON a.DATE = w.DATE
AND a.tmc = w.tmc
LEFT OUTER JOIN pinlocations p
ON w.city = p.cityname
WHERE w.DATE = '" & datepicker_value.Text & "'
AND w.TIME LIKE '" & eventTime.SelectedItem.Value & "'
I have a map which I’m placing pins on based of the p.top and p.left. When I click on this I want to display the city name, the tmc, and then under that all the other information based off the filtered search. In the example above it creates pins on top of pins, making a new one for each field, I want it to be distinct.
I know the distinct command exists, just not sure how to use it in this situation.
Thanks!
Use a
group bymodifier, on the values you want to be distinct.Then use a
group_concaton the values you want to have listed in a comma-separated list.If a left-top coordinate only ever links to one city (as you’d expect), there’s no need to put it inside a
group_concatstatement. Nor does MySQL require* you to put it in thegroup byclause.See:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
* ) you can force MySQL do enforce strict group by rules, but by default it is off.
You cannot use
distincthere, because distinct is an all or nothing affair, it operates in the collectivity of all selected values, not just on one field.