日期:2014-05-18 浏览次数:20549 次
CREATE TABLE tb1(id int,name varchar(200)) INSERT tb1 SELECT 1,'red' UNION ALL SELECT 2,'yellow' UNION ALL SELECT 3,'green' UNION ALL SELECT 4,'red' UNION ALL SELECT 5,'red' CREATE TABLE tb2(id int,remark varchar(200)) INSERT tb2 SELECT 1,'a' UNION ALL SELECT 2,'b' UNION ALL SELECT 3,'c' UNION ALL SELECT 4,'d' UNION ALL SELECT 5,'e' SELECT tb2.* FROM tb1 INNER JOIN tb2 ON tb1.id=tb2.id WHERE tb1.name='red'
------解决方案--------------------
子查询
select * from table2 where id in
(
select id from table1 where...............
)
------解决方案--------------------