在 SQL SERVER ,ACCESS等数据库中可以这样调用:
select * from tableA where id in (select distinct id2 from tableB where type='测试')经过测试发现
MYSQL 可以使用 select * from tableA where id in (2,3)但是就是不能使用上面的第一个SQL语句
也就是说,好像 MYSQL 中的 in 语法只能是固定的,不能用动态查询出来的感觉很不方便请问有没有什么解决方法?谢谢
select * from tableA where id in (select distinct id2 from tableB where type='测试')经过测试发现
MYSQL 可以使用 select * from tableA where id in (2,3)但是就是不能使用上面的第一个SQL语句
也就是说,好像 MYSQL 中的 in 语法只能是固定的,不能用动态查询出来的感觉很不方便请问有没有什么解决方法?谢谢
select a.* from tableA a
inner join
(select distinct id2 from tableB where type='测试') b
on a.id=b.id2
select a.* from tableA a
left join
(select distinct id2 from tableB where type='测试') b
on a.id=b.id2 where b.id2 is not null
select a.* from tableA a
inner join
(select distinct id2 from tableB where type='测试') b
on a.id=b.id2
建议还是用 inner join ,但是要控制好数据输出,否则输出的结果集可能不是你想象中的。
本机上存的,看是MYSQL就装了,后来看一下原来是老古董的3.XXX
呵呵
多谢各位