我建了两个表 一个是text(name,dname)一个是text1(num,item),text表里有一条记录是(安全,text1),我想要通过text表来查询text1中所有值。我用的是select * from (select dname where name='安全');但是错误。请问应该怎么编写代码。谢谢了,急!奖励很高啊!
我试了你的方法,但是最终显示结果跟select dname from text where name='安全';一样
我可以定义一个变量x,查询表text,当name=‘安全’得到的结果text1赋值给这个变量x,这时x值就是text1 select into @x from text where name=‘安全’; 查询TEXT1表, set @ww=concat('select * from ',@x) prepare qq from @ww; execute qq 在SP中直接使用,可以不用定义
DECLARE @te varchar(100) set @te=(select dname where name='安全') exec('select * from ' + @te )
DECLARE @te varchar(100) set @te=(select dname where name='安全') exec('select * from ' + @te )
上述代码是SQLSERVER的,非MYSQL
语法上你需要改成这样,但你的目的是什么呢?select * from (select dname from text where name='安全') t;建议建例说明。
select into @x from text where name=‘安全’;
查询TEXT1表,
set @ww=concat('select * from ',@x)
prepare qq from @ww;
execute qq
在SP中直接使用,可以不用定义
DECLARE @te varchar(100)
set @te=(select dname where name='安全')
exec('select * from ' + @te )
set @te=(select dname where name='安全')
exec('select * from ' + @te )