JackDavis JackDavis - 1 year ago 61
SQL Question

MySQL query in two tables

Is possible to get all items with name = "A" AND status = 1? Name is in table items and status is in table status.

Something like

SELECT * FROM items WHERE name = "A" AND id AS status.itemid = 1
but this does not work.

Db structure:

TABLE items:

id name
1 A
2 A
3 B

TABLE status:

itemid status
1 1
2 1
3 2

Answer Source

use inner join

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download