mysql - Count and group by in same query -


bid_count returning 1 ... how return correct bid count? know it's not returning right count because i'm grouping user_id. can alter query counts also.

"select id, bid, item_id, user_id, max(bid) max_bid, count(bid) bid_count, bid_date   bids   item_id = ?    group user_id order id desc" 

you shouldn't use unaggregated expressions in group unless same within group.

if want return record holding counts user_id, should use subquery counts join them result:

select id, bid, item_id, user_id, bid_date, max_bid, bid_count   bids left join   (select user_id,max(bid) max_bid, count(bid) bid_count      bids     item_id = ?      group user_id ) group_table on bids.user_id = group_table.user_id bids.item_id = ?  

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -