mysql - How Group By works with Duplicates -


i trying insight how sql statements work. right know looking group by , want know, how choose show/return duplicate data.

consider following example:

create table customers  (      firstname  varchar(50),      lastname   varchar(50),      mobileno   varchar(15)  );   insert customers values ('niraj','yadav',989898);  insert customers values ('chetan','gadodia',959595);  insert customers values ('chetan','gadodia',959590);  insert customers values ('atul','kokam',42424242);  insert customers values ('atul','kokam',42424246);  insert customers values ('vishal','parte',9394452);  insert customers values ('vishal','parte',939445);  insert customers values ('vishal','parte',9394451);  insert customers values ('jinendra','jain',12121);  insert customers values ('jinendra','jain',121212);  

if run query...

select    *      customers group  firstname; 

i following results:

firstname  lastname  mobileno   ---------  --------  ---------- atul       kokam     42424242   chetan     gadodia   959595     jinendra   jain      12121      niraj      yadav     989898     vishal     parte     9394452   

so, question is: there reason why returns these particular records? how determine get? i'm using mysql.

in other databases, query not allowed because results unpredictable in case.

notice mysql documentation has case:

mysql handling of group by

the server free choose value each group, unless same, values chosen indeterminate.


i should mention, gordon linoff pointed out me that, starting in version 5.7 of mysql, query yours, unpredictable results possible, no longer allowed default.

info on that: mysql 5.7: only_full_group_by improved, recognizing functional dependencies, enabled default!


Comments