0

I can't read record from column data, why? Code:

$_query = mysqli_query($mysqli , "SELECT  o.id,o.surname,o.name,so.data FROM mowcy AS o
          LEFT JOIN zeb AS so ON so.id=o.id AND so.mowca=o.mowca 
           WHERE 
             o.archiwum = 0 
             AND o.id<>1
             AND o.mowca = 3

              GROUP BY o.id
               ORDER BY ISNULL(o.id) desc, MAX(so.data) ") 
                or die(mysqli_error($mysqli));    

shows an error:

list is not in GROUP BY clause and contains nonaggregated column 'rafik73_tereny.so.data' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Rafik73
  • 51
  • 1
  • 2
  • 13

1 Answers1

2

Try like this;

SELECT  o.id,MAX(so.data) FROM mowcy AS o
          LEFT JOIN zeb AS so ON so.id=o.id AND so.mowca=o.mowca 
           WHERE 
             o.archiwum = 0 
             AND o.id<>1
             AND o.mowca = 3
              GROUP BY o.id
               ORDER BY ISNULL(o.id) desc, MAX(so.data)

As the error directs to you when grouping something in your query, you should just select only grouping fields and aggregated columns.

lucky
  • 12,734
  • 4
  • 24
  • 46
  • **data** does not display any value. **data** exists only in the table **zeb** – Rafik73 Nov 29 '17 at 11:49
  • Check your momcy data and where conditions. "o.archiwum = 0 AND o.id<>1 AND o.mowca = 3" – lucky Nov 29 '17 at 12:08
  • Conditions "o.archiwum = 0 AND o.id<>1 AND o.mowca = 3" are OK. When change MAX(so.data) to so.data in SELECT and add so.data in GROUP BY values of **data** are displayed, but are duplicate. – Rafik73 Nov 29 '17 at 17:53
  • Add alias **maxdata** to MAX(so.data) in SELECT solve problem. Thanks. – Rafik73 Nov 29 '17 at 20:07