ok, so i'm trying to query from a mysql database tables.
any help would be greatly appreciated.
table : buyer
-------------------------------
buyer_id | name
------------------------------
1 | john
2 | sally
table : fruit
------------------------------
fruit_id | fruit
------------------------------
1 | apple
2 | orange
table : purchase
-----------------------------
purchase_id | buyer_id | fruit_id
1 | 1 | 1
2 | 1 | 1
3 | 1 | 2
3 | 2 | 1
i'm trying to have one query that'll output something like this
name | fruit
john | 2x apple, 1x orange
sally | 1x orange
i'd normally use two queries and use php to script it...
but there's got to be a way to do this within mysql with one query.
anyone?
any help would be greatly appreciated.
table : buyer
-------------------------------
buyer_id | name
------------------------------
1 | john
2 | sally
table : fruit
------------------------------
fruit_id | fruit
------------------------------
1 | apple
2 | orange
table : purchase
-----------------------------
purchase_id | buyer_id | fruit_id
1 | 1 | 1
2 | 1 | 1
3 | 1 | 2
3 | 2 | 1
i'm trying to have one query that'll output something like this
name | fruit
john | 2x apple, 1x orange
sally | 1x orange
i'd normally use two queries and use php to script it...
but there's got to be a way to do this within mysql with one query.
anyone?