从多个表中选择id然后按其他方式连接,并按表taha id存在

时间:2016-10-24 06:56:53

标签: php mysql

我在mysql中有这些表: 所有用户在网站上注册的表用户, 表配置文件和列出组表的表组。

我的用户可以注册并提交童年等组。

我想从groups表(profile_childhood,profile_classmate,..)中选择userid,并从用户名和用户名中选择用户名 并指定他们提交的组!

并导致php(BY mysql):

“d yar”是在同学,童年和军事团体中提交的

“rayan”是在儿童组中提交的

“bob”是在同学和儿童团体中提交的

在mysql中:

mysql> select id, username from user;
+-----+----------------+
| id  | username       |
+-----+----------------+
|  96 | didar          |
|  97 | amirecoy       |
|  98 | rayan          |
| 122 | aaaa           |
| 123 | bbbb           |
| 124 | cccc           |
+-----+----------------+

mysql> select userid, name from profile;
+--------+-----------+
| userid | name      |
+--------+-----------+
|     96 | d yar     |
|     97 | amir      |
|     98 | rayan     |
|    122 | alex      |
|    123 | bob       |
|    124 | captain   |
+--------+-----------+

mysql> select t_name, name from groups;
+-------------------+----------------+
| t_name            | name           |
+-------------------+----------------+
| profile_classmate | classmate      |
| profile_martial   | martial_status |
| profile_retiree   | retiree        |
| profile_childhood | childhood      |
+-------------------+----------------+

mysql> select userid from profile_classmate;
+--------+
| userid |
+--------+
|     96 |
|    123 |
+--------+

mysql> select userid from profile_childhood;
+--------+
| userid |
+--------+
|     96 |
|     98 |
|    122 |
|    123 |
|    124 |
+--------+

mysql> select userid from profile_martial;
+--------+
| userid |
+--------+
|     96 |
+--------+

0 个答案:

没有答案