mysql - How can I combine four queries into one query? -
structure of tables:
posts (id, name, user_id, about, time) comments (id, post_id, user_id, text, time) users_votes (id, user, post_id, time) users_favs ( id, user_id, post_id, time)
how can combine these 4 queries (not union
):
select `id`, `name`, `user_id`, `time` `posts` `user_id` = 1 select `post_id`, `user_id`, `text`, `time` `comments` `user_id` = 1 select `user`, `post_id`, `time` `users_votes` `user` = 1 select `user_id`, `post_id`, `time` `users_favs` `user_id` = 1
should use join
s?
what sql query be?
you don't want join these together.
the kind of join
you'd use retrieve end doing cross-product of rows finds. means if had 4 posts, 2 comments, 3 votes, , 6 favorites you'd 4*2*3*6 rows in results instead of 4+2+3+6 when doing separate queries.
the time you'd want join
when 2 things intrinsically related. is, want retrieve posts associated favorite, vote, or comment.
based on example, there's no such commonality in these things.
Comments
Post a Comment