Here are the two queries that I am using, I want to group by description.
The first query returns the correct information, just duplicat himbeeren, apfel.
In the second resultset, hänchenbrust should be entry 12 and paprika should be 13. Instead they are 6 and 8 respectivly.
I do order by date so that I can get the latest 10 entries, but I want to display them alphabetically to the user. Any ideas how to do this?
Thanks,
Sonya
SELECT a.uf_id, a.user_id, a.food_id, a.datetime, a.amount, b.food_id, b.food_desc
FROM user_food a, food b
WHERE 1 AND a.user_id =3 AND a.food_id = b.food_id
ORDER BY a.datetime DESC
LIMIT 0 , 10
returns:
uf_id user_id food_id datetime amount food_id food_desc
310 3 70 2004-06-24 13:22:57 100 70 Himbeeren
309 3 70 2004-06-24 13:22:28 100 70 Himbeeren
320 3 129 2004-02-14 13:33:31 100 129 Pfifferlinge
556 3 59 2004-02-11 13:14:00 100 59 Birne
557 3 70 2004-02-11 13:14:00 100 70 Himbeeren
555 3 50 2004-02-11 13:13:00 100 50 Apfel
554 3 70 2004-02-11 13:07:00 100 70 Himbeeren
538 3 50 2004-02-11 12:37:01 200 50 Apfel
534 3 59 2004-02-11 10:53:00 300 59 Birne
535 3 334 2004-02-11 10:53:00 200 334 Joghurt, entrahmte Milch
SELECT a.uf_id, a.user_id, a.food_id, a.datetime, a.amount, b.food_id, b.food_desc
FROM user_food a, food b
WHERE 1 AND a.user_id =3 AND a.food_id = b.food_id
GROUP BY b.food_desc
ORDER BY a.datetime DESC
LIMIT 0 , 10
returns:
uf_id user_id food_id datetime amount food_id food_desc
320 3 129 2004-02-14 13:33:31 100 129 Pfifferlinge
525 3 346 2004-02-10 10:02:58 25 346 Doppelrahmfrischkäse, 60% i.Tr
524 3 393 2004-02-10 10:02:46 25.5 393 Wasa Mjolk
471 3 99 2004-02-09 14:37:32 100 99 Blumenkohl
469 3 334 2004-02-09 14:37:02 150 334 Joghurt, entrahmte Milch
468 3 127 2004-02-09 14:36:32 50 127 Paprika gedünstet
443 3 109 2004-02-08 13:17:37 100 109 Feldsalat Rapunzel
439 3 205 2004-02-08 12:53:01 400 205 Hänhchenbrust
338 3 70 2004-02-07 14:02:16 100 70 Himbeeren
435 3 330 2004-02-07 12:50:01 500 330 Buttermilch