MySQL: Non Aggregated column is returning values at random [duplicate]

33
January 12, 2019, at 00:50 AM

This question already has an answer here:

  • Get records with max value for each group of grouped SQL results 17 answers
  • SQL: Group by minimum value in one field while selecting distinct rows 7 answers

I am having trouble in querying a table where I would like to have the minimum value of a column in a group. However, when I group the column together in order to clean the table, I get random values in the non group by columns.

I sort of understand why its doing that because I read this link https://www.psce.com/en/blog/2012/05/15/mysql-mistakes-do-you-use-group-by-correctly/. But even with his solution I am still a bit confused.

Here is the table

LastName  | FirstName  | Weight |   Birthday   
---------- ------------ -------- ------------ 
Conner      Sarah           123    1996-12-01  
Conner      Michael         180    1998-12-01  
Conner      Jim             120    2000-12-01  
Jackson     Mike            154    1957-09-09  
Jackson     Leslie          145    2009-03-02  
Seven       James           120    2000-01-10  
Seven       Alice           130    1990-01-10

I queried for the min date and grouped by LastName so that I would get the youngest member of each family but the weight column returned is random, picking a random weight from any family member. Is there any way to fix this?

Thanks

READ ALSO
Table to show the latest results from SQL

Table to show the latest results from SQL

I have a page to increase the tracking on Facebook, I created a table to display the latest results in the id column, but this table shows the oldest results for the highest resultsPlease help me edit the table to show the latest results

46
Xampp connects to MariaDB instead of mysql (KNP/SymfonyCasts tutorial “how to speak database”)

Xampp connects to MariaDB instead of mysql (KNP/SymfonyCasts tutorial “how to speak database”)

I am following tutorial from KNP/SymfonyCasts and I have problem with connecting to mysql

47
Django project, I need advice about my model

Django project, I need advice about my model

I need for my users to be able to save the body and slug fields from my Post model in my database, but I have an issueI have 10 fields named body1, body2 etc

19
SQL Statement Multiple Join Query Not Working

SQL Statement Multiple Join Query Not Working

I have a table called contracts and table called feedbackI also have table users with 3 users - with ids = 3, 8 and 10

29