Help for a sql query
Posted: Wed Sep 28, 2011 11:05 pm
Imagine there are two tables like below.
Table1:
Table2:
I want to select all the posts by all users who has the group_id "promo".
It can do by getting "promo" group members' ids from table1 and selecting all topics made by those ids from table2.
But when those tables being larger this can be a very slower way.
Please tell me a one sql query to do that.
(I'm using PHP & Mysql)
Table1:
user_id | user_name | group_id |
1 | neo | admin |
2 | rksk | promo |
3 | nipuna | promo |
4 | face | promo |
5 | herath | help |
6 | saman | user |
7 | magneto | mod |
8 | x | user |
9 | y | user |
. | ||
. | ||
. |
post_id | title | text | user_id |
. | |||
. | |||
. |
It can do by getting "promo" group members' ids from table1 and selecting all topics made by those ids from table2.
But when those tables being larger this can be a very slower way.
Please tell me a one sql query to do that.
(I'm using PHP & Mysql)