Suppose this table: posts_groups
+
| post_id | group_id | type |
+
| 1 | 1 | public | // group
+
And the table: posts
+
| id | type |
+
| 1 | public | // example : post
+
Query1
SELECT post_id FROM posts_groups pg
JOIN posts p ON p.id = pg.post_id
WHERE group_id = 1 AND pg.type = public
Well, this control group is 1 and the type FROM CURRENT table , then select some post_id.
Query2
SELECT post_id FROM posts_groups pg
JOIN posts p ON p.id = pg.post_id
WHERE group_id = 1 AND p.type = public
this query also does the same. but checking out the type FROM POSTS table .
But which method is faster and has better performance. any idea how these two queries work.
PROCESS TERMS!
in query 1, it says if (group_id = 1 AND p.type = public) THEN if (post.id = posts_groups.id) JOIN posts
in query 2, it says if (group_id = 1) THEN , if (post.id = posts_groups.id) THEN , if (posts.type = public) JOIN messages.
Processquery2 . , , .
.