PHP mysql关联查询问题 20
mysql>select*fromtablea;+------+----------+------+----------+------------+|id|name|ty...
mysql> select * from tablea;
+------+----------+------+----------+------------+
| id | name | typeid| time |activityid |
+------+----------|------+------------------------|
| 1 | zhangsan | 1 | 121324335|2 |
| 2 | zhangsan | 2 | 423432563|2 |
+------+----------+------+-------------------------
3 rows in set (0.00 sec)
mysql> select * from tableb;
+------+----------+-----------|
| id | name |activityid |
+------+----------|-----------|
| 1 | a |2 |
| 2 | b |2 |
+------+----------+------+----
| 3 | c |2 |
+------+----------|------+-----
这俩表如何关联才可以得到结果(关联字段是activityid,typeid是tableb中的id)
Array
(
[0] => Array
(
[activityid]=>2
[name] => zhangsan
[book] => Array
(
[0] => Array
(
[time] => 1463056411
[typeid] => 1
)
[1] => Array
(
[yime] => 1463076411
[typeid] => 3
)
[0]=>Array
(
[yime] =>
[typeid] => 3
)
)
)
) 展开
+------+----------+------+----------+------------+
| id | name | typeid| time |activityid |
+------+----------|------+------------------------|
| 1 | zhangsan | 1 | 121324335|2 |
| 2 | zhangsan | 2 | 423432563|2 |
+------+----------+------+-------------------------
3 rows in set (0.00 sec)
mysql> select * from tableb;
+------+----------+-----------|
| id | name |activityid |
+------+----------|-----------|
| 1 | a |2 |
| 2 | b |2 |
+------+----------+------+----
| 3 | c |2 |
+------+----------|------+-----
这俩表如何关联才可以得到结果(关联字段是activityid,typeid是tableb中的id)
Array
(
[0] => Array
(
[activityid]=>2
[name] => zhangsan
[book] => Array
(
[0] => Array
(
[time] => 1463056411
[typeid] => 1
)
[1] => Array
(
[yime] => 1463076411
[typeid] => 3
)
[0]=>Array
(
[yime] =>
[typeid] => 3
)
)
)
) 展开
3个回答
展开全部
"select * from 收藏表 as A,用户表 as B where A.user_id=B.user_id and A.user_id='张三'";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-06-07
展开全部
SELECT * FROM tablea AS a JOIN tableb AS b ON a.typeid = b.id;
追问
这样不对 只查出来两条 没有那个空的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询