I basically have two tables:
A(id int, name varchar(10), info varchar(10))
B(id int, item varchar(10))
A
1 A Hello
2 B World
3 C Foo
B
1 apple
1 orange
1 hammer
2 glass
2 cup
Using the following query...
mysql> SELECT a.id, a.name, a.info, group_concat(b.item SEPARATOR ' ')
FROM a
LEFT OUTER JOIN b ON (a.id=b.id)
GROUP BY 1,2,3;
I get the desired output:
+------+------+-------+------------------------------------+
| id | name | info | group_concat(b.item separator ' ') |
+------+------+-------+------------------------------------+
| 1 | A | Hello | apple orange hammer |
| 2 | B | World | glass cup |
| 3 | C | Foo | NULL |
+------+------+-------+------------------------------------+
I would now like to modify the query to get a result table containing the same information but only those who have items starting with the letter o, (like 'o%')
How do I get the following output?
+------+------+-------+------------------------------------+
| id | name | info | group_concat(b.item separator ' ') |
+------+------+-------+------------------------------------+
| 1 | A | Hello | apple orange hammer |
+------+------+-------+------------------------------------+
Note that I still want to present the whole string 'apple orange hammer'
, not only 'orange'