mysql - Group by with where clause with having count equal to 1 -


objective: find rows (1) number of messages number 1, , (2) length of message less 5 characters in length. can each separately, having difficulty when combine 2 conditions in 1 sql query.

sample database table: +-----+----------+----------+ | id  | number   | message  | +-----+----------+----------+ |   1 |      100 | test     | |   2 |      100 | testing  | |   3 |      100 | testing  | |   4 |      200 | test     | |   5 |      201 | test     | |   6 |      201 | test     | |   7 |      250 | testing  | |   8 |      251 | test     | |   9 |      300 | testing  | |  10 |      300 | testing  | +-----+----------+----------+ 

should return rows 200 , 251. tried following, no luck:

select * `reports` length(message) < 5 group number having count(*) = '1' 

returns rows rows contains counts > 1.

ok, made wrong change few hrs ago - time have data yours. ah, , see you're having problem with. don't understand order mysql interprets select; it's first doing limit results group by. working designed.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -