mysql - SQL VIEW only returning first record -
i'm not sure going on here. have created mysql view , grab data out of 4 different tables seems returning first record.
create or replace view request_view select trequest.id, trequest.minutes_required, trequest.expires_at, user.name author, trequest.abstract_text, trequest.full_text, tgroup.name tgroup, sum(torder.minutes) total_minutes trequest join user on trequest.author_id = user.id left join tgroup on trequest.group_id = tgroup.id left join torder on trequest.id = torder.request_id order trequest.created_at;
when try select against view return first record:
mysql> select id request_view; +----+ | id | +----+ | 1 | +----+ 1 row in set (0.00 sec) mysql> select id request_view id=2; empty set (0.00 sec)
i have 30 trequest rows... there anyway can view return of trequest records? or using view incorrectly?
you're doing sum
without group by
. sum
aggregate function make sense on group of rows. if don't specify columns group by, default take sum on rows, means 1 result.
if want 1 row each column in trequest
, try adding group trequest.id
view definition.
Comments
Post a Comment