I have a table in which each hundret rows have the same id (see “chart_id” in shortened Example below).
If we consider every row with the same “chart_id” a “chart” how do I select every chart having a certain year in it with a mysql query.
For example how do I select every chart with 2009 in it (chart2 and chart3):
edit:
rows with id 4,5,6 and 7,8,9 should be selected if I look for 2009.
id chart_id time
1 1 2008
2 1 2008
3 1 2008
4 2 2008
5 2 2008
6 2 2009
7 3 2009
8 3 2009
9 3 2009
10 4 2010
11 4 2010
12 4 2010
Any suggestions?
Thanks 🙂
Just use
DISTINCT:Or, do you mean you want all the rows for that chart SQL Fiddle: