显示具有两个查询的组ID

时间:2014-08-20 15:35:26

标签: php

我希望你能帮助我:)。

Table client_access:

+-----------------------------------------------+
| id | group_id | email  | firstname | lastname |
+-----------------------------------------------+
| 1  |    2     | e@ss.s | john      | terry    |
+-----------------------------------------------+
| 2  |    1     | b@ss.s | Marie     |  joli    |
+-----------------------------------------------+

Table client_group:

+-----------------------------------------------+
| id |    name         | descri     | color     |
+-----------------------------------------------+
| 1  |    Gooduser     | good users | #000      |
+-----------------------------------------------+
| 2  |    Baduser      | bad users  | #ff0      | 
+-----------------------------------------------+

我想要打印:

Client: John terry 
Group: baduser
Color: #ff0

也许有人可以帮您创建此查询?

1 个答案:

答案 0 :(得分:-1)

我做了:))

SELECT *, (SELECT name FROM client_group WHERE id=o.group_id) AS gname, (SELECT color FROM client_group WHERE id=o.group_id) AS gcolor, (SELECT id FROM hb_client_access WHERE id=o.id) AS guser FROM  client_access AS o WHERE id='".$userid."' LIMIT 1

感谢所有