NILAY PATEL NILAY PATEL - 5 months ago 23
MySQL Question

Group By query in MySQL not working properly

I make a query to find the last 24 results from three different tables.

The query is :

SELECT m.MovID,m.Type,m.Image,m.Date,t.SerID,t.Type,t.Image,t.Date,g.GamID,g.Type,g.Image,g.Date
FROM movie m, tvseries t, games g
GROUP BY m.MovID, t.SerID, g.GamID
LIMIT 0,24

but in the result of this query group by is not working.


The GROUP BY is not the problem (at least not the major one).

Th real problem is that you selecting data from 3 tables without joining them. This part of your query:

from   movie m
       , tvseries t
       , games g 

meanss all combinations of every row of the 1st table with every row of the 2nd with every row of the 3rd table. Is that what you want?

FROM   movie m
  CROSS JOIN  tvseries t
  CROSS JOIN  games g 

Most probably you want to JOIN the 3 tables:

FROM   movie m
  INNER JOIN  tvseries t
    ON  t.someColumn = m.someColumn 
  INNER JOIN  games g 
    ON  g.someOtherColumn = m.someOtherColumn