/**************************************************************************************/
/* File:        demo20                                                                */
/* Project:     ATSQL2                                                                */
/* Author:      Michael Boehlen                                                       */
/* Date:        23-08-1995                                                            */
/* Results:                                                                           */
/**************************************************************************************/

SET CALENDRIC SYSTEM fiscal;

/* sn tables */
/*************/
create table p(a integer);

select * from p;
/* empty table */
select a from p;
/* empty table */
select b from p;
/* error: column 'b' does not exist */
valid select * from p;
/* !!!error: 'p' is not a vt table */

insert into p values(1);
insert into p values(2);

/* simple queries */
/******************/
select * from p;
/* <1>,<2> */
select a from p;
/* <1>,<2> */
select valid(p) from p;
/* error!!!: 'p' is not a vt table */
select transaction(p) from p;
/* error!!!: 'p' is not a tt table */
valid select * from p;
/* !!!error: 'p' is not a vt table */
transaction select * from p;
/* !!!error: 'p' is not a tt table */
nonsequenced valid select a from p;
/* <1>,<2> */
nonsequenced valid period '1910-1920' select * from p;
/* <1||1910-1920>,<2||1910-1920> */
nonsequenced transaction select * from p;
/* <1>,<2> */
nonsequenced transaction period '1910-1920' select * from p;
/* error!!!: tt may not be specified by the user */
valid and transaction select * from p;
/* !!!error: 'p' is not a vt/tt table */
transaction and valid select * from p;
/* !!!error: 'p' is not a vt/tt table */
valid and nonsequenced transaction select * from p;
/* !!!error: 'p' is not a vt table */
nonsequenced transaction and valid select * from p;
/* !!!error: 'p' is not a vt table */

create table q(a number(5), b char(3));
create table q(a integer, b char(6));
insert into q values (1,'a');
insert into q values (1,'a');
insert into q values (3,'a');
insert into q values (3,'b');

/* joins */
/*********/
select * from p,q;
/* <1,1,'a'>,<1,1,'a'>,<1,3,'a'>,<1,3,'b'>,
   <2,1,'a'>,<2,1,'a'>,<2,3,'a'>,<2,3,'b'> */
select * from p,q where p.a=q.a;
/* <1,1,'a'>,<1,1,'a'> */
select q.* from p,q where p.a=q.a;
/* <1,'a'>, <1,'a'> */
select p.a from p,q where p.a=q.a;
/* <1>, <1> */

/* !!!set operations (union, except) */
/**********************************/
select * from p except select * from q;
/* !!!bogus set operation (number of columns don't match) */
select * from p except select a from q;
/* !!!<2> */
select * from p except select b from q;
/* incompatible column types in set operation */
select a from q except select a from p;
/* <3>, <3> */
/* Oracle: <3> */
select a from q except all select * from p;
/* <1>, <3>, <3> */
/* 'except all' not implemented */  
select * from p union select * from p;
/* <1>,<2>,<1>,<2> */
/* Oracle: <1>,<2> */

/* subqueries (duplicates) */
/***************************/
select a1.* from q as a1, q as a2 where a1.a=a2.a and a1.a=1;
/* <1,'a'>,<1,'a'>,<1,'a'>,<1,'a'> */
select distinct a1.* from q as a1, q as a2 where a1.a=a2.a and a1.a=1;
/* <1,'a'> */
select a1.* from q as a1 where exists 
  (select * from q as a2 where a1.a=a2.a) and a1.a=1;
/* !!!<1,'a'>,<1,'a'> */
select distinct a1.* from q as a1 where exists 
  (select * from q as a2 where a1.a=a2.a) and a1.a=1;
/* <1,'a'> */
select * from q where not exists (select * from p where p.a=q.a);
/* <3,'a'>,<3,'b'> */
select a from q where not exists (select a from p where q.a=p.a);
/* <3>,<3> */
select distinct a from q where not exists (select a from p where q.a=p.a);
/* <3> */

drop table p;
drop table q;
