Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group By query in MySQL not working properly

Tags:

mysql

group-by

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.

like image 568
NILAY PATEL Avatar asked Feb 02 '26 06:02

NILAY PATEL


1 Answers

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 
like image 171
ypercubeᵀᴹ Avatar answered Feb 04 '26 00:02

ypercubeᵀᴹ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!