我是新的SQL查询,
我在这里有问题..
我如何使用查询来查询不同的表?
Table member_list Table member_history
+-----------+--------+ +-----------+--------+
| member_id | gender | | member_id | spend |
+-----------+--------+ +-----------+--------+
| 1 | 1 | | 1 | 100 |
| 2 | 2 | | 2 | 150 |
| 3 | 1 | | 1 | 75 |
+-----------+--------+ | 3 | 240 |
| 1 | 290 |
+-----------+--------+
$query1 = mysql_query("SELECT * FROM member_list where gender = 1");
$query2 = mysql_query("SELECT spend FROM member_history WHERE spend < 250");
从上面查询$ query1将导致member_id:1,3和$ query2将导致1(100),2(150),1(75),3(240)
我的问题是:
答案 0 :(得分:0)
使用JOIN
SELECT * FROM member_list ml join member_history mh
on ml.member_id=mh.member_id
where gender = 1 and spend < 250