Im trying to get some stats; total links, users and views, from 3 different tables. What im trying:
SELECT SUM(p.views), COUNT(c.id), COUNT(u.id)
FROM studenkel_userprefs as p, studenkel_content as c, studenkel_users as u
If I do them individually in three different queries, they work fine, but togheter the results gets a couple thousand times higher than what i want. I guess they multiply eachother in some way, Tips?
Thanks
Edit: Thanks guys, really appreciate your help, sorted it out.
FROM studenkel_userprefs as p, studenkel_content as c, studenkel_users as uit will give you a Cartesian product for all the rows from the three tables, it is also calledCROSS JOINyou should useINNER JOINbut you need to specify how the three tables relate to each other, please update your question and show how they are related.JOINsyntax, and tell the DB HOW those tables relate to each other, e.g. in this exact case you need a where clause:... WHERE studenkel_userprefs.foo = studenkel_content.bar AND etc....