MySQL查询在两个表中

时间:2016-07-17 21:23:12

标签: mysql sql

可以获得名称=" A" AND status = 1?名称在表项中,状态为表状态。

SELECT * FROM items WHERE name = "A" AND id AS status.itemid = 1这样的东西,但这不起作用。

Db结构:

表项目:

id      name
1       A
2       A
3       B

TABLE状态:

itemid      status
1           1
2           1
3           2

1 个答案:

答案 0 :(得分:1)

使用内部联接

select a.name, b.status 
from  items as a 
inner join status as b  on a.id = b.itemid
where a.name ='A' and b.status =1;