--
-- ### Multiple view references in a query
--
 

drop if exists table t1;

create table t1 ( a int, b string(10));

drop if exists table t2;

create table t2 ( a int, b string(10));

insert into t1 values ( 1, 'XXX');
insert into t1 values ( 2, 'XXX');
insert into t1 values ( 3, 'XXX');
insert into t1 values ( 4, 'XXX');
insert into t1 values ( 5, 'XXX');
insert into t1 values ( 6, 'XXX');
insert into t1 values ( 7, 'XXX');

insert into t2 values ( 1, 'XXX');
insert into t2 values ( 2, 'XXX');
insert into t2 values ( 3, 'XXX');

drop if exists view v1;
create view v1 as select a as ax, ( select count(ty.a) from t2 ty order by a ) as b from t1 where a < 10;

select * from v1;

select * from v1 where exists ( select ax from v1 );

select * from v1;
select ax from v1 vx; 
