我需要从表1中找到group id = 1的项目(结果1) 然后那些组ID为1的项目,转到表2过滤结果1 +只选择那些价格id = 200 表1,项目ID,组ID 表2,项目ID,价格ID
我尝试过选择内连接但无法过滤。 union all返回错误,因为列数据不相同。
select item id, group id
from table 1
where groupid = '1'
inner join
select item id, price id
from table 2
where price id = '200'
答案 0 :(得分:0)
尝试
select * from table2 as t2 inner join (select * from table1 where groupid=1) as t1
on t1.itm_id =t2.itm_id where t2.price_id=200
答案 1 :(得分:0)
你有什么尝试?是这样的吗?
SELECT t1.a,
t1.b,
t1.c,
t2.x,
t2.y
FROM t1
inner join t2
ON t1.KEY = t2.KEY
WHERE t1.grpid = 1
AND t2.priceid = 200;