Books Catalog Database

This is a sample database used in Oracle Database 10g course. This contains tables to store details regarding publishers, titles, and authors.

In this article, you find the following:

Structure of Tables

The following are the table used in this application. Columns displayed in red color are primary keys. Arrows point from foreign key to corresponding prarent key.

Creating tables and inserting data

Log on to Oracle and type the following commands at SQL prompt in SQL*Plus to create the requried tables. The following script not only creates the tables, it also inserts some data into the tables.

Copy these commands from here and past them into SQL*Plus to run them.


CREATE TABLE PUBLISHERS
(
    PUBID      NUMBER(3)  CONSTRAINT  PUBLISHERS_PK PRIMARY KEY,
    PNAME      VARCHAR2(30),
    EMAIL      VARCHAR2(50) CONSTRAINT PUBLISHERS_EMAIL_U UNIQUE,
    PHONE      VARCHAR2(30)
);


CREATE TABLE  SUBJECTS
(
    SUBID      VARCHAR2(5)  CONSTRAINT  SUBJECTS_PK PRIMARY KEY,
    SNAME      VARCHAR2(30)
);


CREATE TABLE  AUTHORS
(
    AUID     NUMBER(5)  CONSTRAINT  AUTHORS_PK PRIMARY KEY,
    ANAME      VARCHAR2(30),
    EMAIL      VARCHAR2(50) CONSTRAINT AUTHORS_EMAIL_U UNIQUE,
    PHONE      VARCHAR2(30)
);



CREATE TABLE  TITLES
(
    TITLEID    NUMBER(5)   CONSTRAINT  TITLES_PK PRIMARY KEY,
    TITLE      VARCHAR2(30),
    PUBID      NUMBER(3)   CONSTRAINT  TITLES_PUBID_FK REFERENCES PUBLISHERS(PUBID),
    SUBID      VARCHAR2(5) CONSTRAINT  TITLES_SUBID_FK REFERENCES SUBJECTS(SUBID),
    PUBDATE    DATE,
    COVER      CHAR(1)     CONSTRAINT  TITLES_COVER_CHK  CHECK ( COVER IN ('P','H','p','h')),
    PRICE      NUMBER(4)
);


CREATE TABLE  TITLEAUTHORS
(
    TITLEID    NUMBER(5)  CONSTRAINT  TITLESAUTHORS_TITLEID_FK REFERENCES TITLES(TITLEID),
    AUID       NUMBER(5)  CONSTRAINT  TITLESAUTHORS_AUTHID_FK REFERENCES AUTHORS(AUID),
    IMPORTANCE NUMBER(2),
    CONSTRAINT  TITLESAUTHORS_PK  PRIMARY KEY(TITLEID,AUID)
);


INSERT INTO SUBJECTS VALUES ('ORA','ORACLE DATABASE 10g');
INSERT INTO SUBJECTS VALUES ('JAVA','JAVA LANGUAGE');
INSERT INTO SUBJECTS VALUES ('JEE','JAVA ENTEPRISE EDITION');
INSERT INTO SUBJECTS VALUES ('VB','VISUAL BASIC.NET');
INSERT INTO SUBJECTS VALUES ('ASP','ASP.NET');



INSERT INTO PUBLISHERS VALUES (1,'WILLEY','WDT@VSNL.NET','91-11-23260877');
INSERT INTO PUBLISHERS VALUES (2,'WROX','INFO@WROX.COM',NULL);
INSERT INTO PUBLISHERS VALUES (3,'TATA MCGRAW-HILL','FEEDBACK@TATAMCGRAWHILL.COM','91-11-33333322');
INSERT INTO PUBLISHERS VALUES (4,'TECHMEDIA','BOOKS@TECHMEDIA.COM','91-11-33257660');



INSERT INTO AUTHORS VALUES (101, 'HERBERT SCHILD','HERBERT@YAHOO.COM',NULL);
INSERT INTO AUTHORS VALUES (102, 'JAMES GOODWILL','GOODWILL@HOTMAIL.COM',NULL);
INSERT INTO AUTHORS VALUES (103, 'DAVAID HUNTER','HUNTER@HOTMAIL.COM',NULL);
INSERT INTO AUTHORS VALUES (104, 'STEPHEN WALTHER','WALTHER@GMAIL.COM',NULL);
INSERT INTO AUTHORS VALUES (105, 'KEVIN LONEY','LONEY@ORACLE.COM',NULL);
INSERT INTO AUTHORS VALUES (106, 'ED. ROMANS','ROMANS@THESERVERSIDE.COM',NULL);



INSERT INTO TITLES VALUES (1001,'ASP.NET UNLEASHED',4,'ASP','12-APR-02','P',540);
INSERT INTO TITLES VALUES (1002,'ORACLE10G COMP. REF.',3,'ORA','1-MAY-05','P',575);
INSERT INTO TITLES VALUES (1003,'MASTERING EJB',1,'JEE','3-FEB-05','P',475);
INSERT INTO TITLES VALUES (1004,'JAVA COMP. REF',3,'JAVA','3-APR-05','P',499);
INSERT INTO TITLES VALUES (1005,'PRO. VB.NET',2,'VB','15-JUN-05','P',450);



INSERT INTO TITLEAUTHORS VALUES (1001,104,1);
INSERT INTO TITLEAUTHORS VALUES (1002,105,1);

INSERT INTO TITLEAUTHORS VALUES (1003,106,1);

INSERT INTO TITLEAUTHORS VALUES (1004,101,1);

INSERT INTO TITLEAUTHORS VALUES (1005,103,1);
INSERT INTO TITLEAUTHORS VALUES (1005,102,2);

Queries with answers

  1. Display number of books published in the current year
    select count(*) from titles where to_char(sysdate,'yyyy') = to_char(pubdate,'yyyy');
    
  2. Display publisher ID and maximum price for books on subject ORACLE.
    select pubid, max(price)
    from title
    where subid = 'ora'
    group by pubid;
    
  3. Display Subject ID and max price.
    select subid, max(price)
    from titles
    group by subid;
    
  4. Display Subject ID and number of books of that subject with price more than 500.
    select subid, count(*)
    from titles
    where price > 500
    group by subid;
    
  5. Display Subject ID, Publisher ID and average price.
    select subid,pubid, avg(price)
    from titles
    group by subid,pubid;
    
  6. Display month and number of books published for each month in the current year.
    select to_char(pubdate,'mm'), count(*) nobooks
    from titles
    where to_char(sysdate,'yyyy') = to_char(pubdate,'yyyy')
    group by to_char(pubdate,'mm');
    
  7. Display Title ID and number of authors of the title.
    select titleid, count(*)
    from titleauthors
    group by titleid;
    
  8. Display how many titles author 103 wrote as the lead author.
    select count(*)
    from titleauthors
    where importance = 1  and auid = 103;
    
  9. Display Publisher name and number of books published.
    select pname, count(*)
    from   publishers p, titles t
    where  p.pubid = t.pubid
    group  by pname;
    
  10. Display the publisher who published more than 3 books on JAVA
    select pubid
    from   titles
    where  subid = 'JAVA'
    group  by pubid
    having count(*) > 3;
    
  11. Display Publisher name and number of books published.
    select pname, count(*)
    from   publishers p, titles t
    where  p.pubid = t.pubid
    group  by pname;
    
  12. Display the author who wrote more than 3 titles in last two years.
    select auid
    from   titleauthors ta, titles t
    where  months_between(sysdate,pubdate) <= 24
    group  by auid
    having count(*) > 3;
    
  13. Display the subjects for which we have the average price in the range 300 to 400
    select subid from titles
    group by subid
    having avg(price) between 300 and 400;
    
  14. Display the subject having maximum price and minimum price
    select subid,max(price), min(price)
    from titles
    group by subid;
    
  15. Display author name and maximum price of all the books written by the authors
    select aname, max(price)
    from authors a, titleauthors ta, titles t
    where  t.titleid = ta.titleid and a.auid = ta.auid
    group by aname;
    
  16. Display names of the authors who wrote a book with price <500
    select aname from authors
    where auid in (select auid from titleauthors where titleid in
                            (select titleid from titles where price < 500) );
    
  17. Display authors who wrote a book on ORACLE.
    select * from authors
    where auid in (select auid from titleauthors where titleid in
                            (select titleid from titles where subid = 'ora') );
    
  18. Display subjects in which minimum price <300 maximum price >600
    select * from subjects
    where subid in
      ( select subid
        from  titles
        group by subid
        having min(price) < 300)
    and   subid in
      ( select subid
        from  titles
        group by subid
        having max(price) > 600);
    
    
  19. Display the author who has written the costliest book.
    select * from authors
    where auid  =
      ( select auid from titleauthors
        where titleid =
               (select titleid from titles
                where price =
                         (select max(price) from titles)
               )
      );
    
    
  20. Display the author who wrote a book with price >500.
    select * from authors
    where auid  =
      ( select auid from titleauthors
        where titleid =
               (select titleid from titles where price > 500)
      );
    
    
  21. Display the subject for which we have more than 3 books published in the current year
    select * from subjects
    where subid in
      (select subid
       from titles
       where to_char(pubdate,'yyyy') = to_char(sysdate,'yyyy')
       group by subid
       having count(*) > 3);
    
  22. Display author name and title of the books for which author is the lead author
    select aname,title
    from titles t, authors a, titleauthors ta
    where t.titleid = ta.titleid and a.auid = ta.auid
    and importance = 1;
    
  23. Display author and number of books by the author from publisher WROX
    select auid,count(*)
    from titles
    where pubid =
       (select pubid from publishers where pname = 'WROX');
    
  24. Display year and number of books published where the book is written by more than one author
    select to_char(pubdate,'yyyy') , count(*)
    from titles
    where  titleid in
         (select titleid
          from titleauthors
          group by titleid
          having count(*) > 1)
    group by to_chat(pubdate,'yyyy');
    
    
  25. Display the subjects where the difference between minimum price and maximum price is>200
    select * from subjects
    where subid in
      ( select subid
        from titles
        group by subid
        having max(price) - min(price) > 200);
    
  26. Change the price of title 1003 to the price of the title most recently published
    update titles set price =
     ( select price from titles
       where  pubdate = ( select max(pubdate) from titles )
    where  titleid = 1003;
    
  27. Display the authors who wrote a book in the previous year but not in the current year
    select  * from authors
    where auid in
      ( select auid
        from titleauthors ta, titles t
        where ta.titleid = t.titleid and  to_chat(pubdate,'yyyy') = to_char(sysdate,'yyyy')  - 1
      )
    and auid not in
      ( select auid
        from titleauthors ta, titles t
        where ta.titleid = t.titleid and  to_chat(pubdate,'yyyy') = to_char(sysdate,'yyyy')
      );
    
    
  28. Display the publishers who published a book on ORACLE but no book on JAVA.
    select  * from publishers
    where pubid in
      ( select pubid
        from  titles
        where subid = 'ORA');
      )
    and pubid not in
      ( select pubid
        from  titles
        where subid = 'JAVA')
      );
    
    
  29. Display year the highest price by taking into account books that are written by more than one author.
    select to_char(pubdate,'yyyy') , max(price)
    from titles
    where  titleid in
         (select titleid
          from titleauthors
          group by titleid
          having count(*) > 1)
    group by to_chat(pubdate,'yyyy');
    
    
  30. Change the Publisher date of title 1003 to least publishing date of any book of that subject in the same year
    update titles t set pubdate =
       ( select min(pubdate)
         from titles where  subid = t.subid
         and  to_chat(pubdate,'yyyy') = to_chat(t.pubdate,'yyyy')
       )
    where titleid = 1003;
    
    

Queries with answers for 17-Feb-2006 Batch

  1. Display employees where name ends with n and salary is less than 5000.
    select * from emp where ename like '%n' and sal<5000
    
  2. Display name,salary and department of the employees where name of the employee contains 'a' twice.
    select ename,sal,job from emp where ename like '%a%a%';
    
  3. Display the employees where the commission is present and also calculate the commission on salary and display it.
    select ename,sal*comm comm from emp where comm is not null;
    
  4. Display the employees who joined after 1st Jan 2000.
    select * from emp where hire_date>'01-Jan-2000';
    
  5. Display the employees with salary more than 5000 and job is Clerk.
    select * from emp where sal>5000 and job='clerk'
    
  6. Increase the salaries of the department number 10 by 10%.
    update emp set sal = sal * 1.1 where deptno = 10;
    
  7. Change the date of joining for employee 7369 to '05-Mar-2001'.
    update emp set hiredate = '05-mar-2001' where empno = 7369;
    
  8. Display employee name, salary rounded to 100's,hra rounded to 10's (hra is 25% of the salary).
    select ename, round(sal,-2) salary, round(salary *  0.25)  hra from emp; 
  9. Display the employees who joined in the last 6 months.
    select * from emp where  months_between(sysdate,hiredate) <= 6;
    
  10. Display employee name,hiredate and the date on which the first salary was paid.(The salary is paid on 1st of every month)
    select ename,hiredate, last_day(hiredate) + 1 salarydate from emp;
    
  11. Display employee name and first saturday since he joined and salary for all employees who have more than 3 years of experience.
    select ename, next_day(hiredate,'sat') , sal from emp where  months_between(sysdate,hiredate) > 36;
    
  12. Display names of the employees if employee name contains more than 10 characters and also contains letters s and i(in any case)
    select ename from emp where length(ename)>=10 and upper(ename) like '%S%I%'
    
  13. Display employee number and the position at which letter 'i' appears in employee name for employees where name contains 'i'.
    select empno, instr(ename,'i') from emp where ename like '%i%';
    
  14. Replace the leading zeroes in employee id with *.
    select  lpad(ltrim(empno,'0'),5,'*')  from emp;
    
  15. Display the last three characters of employee name.
    select  substr(ename, length(ename)-2) from emp;
    
  16. Display employee name,department no and job by concatenating deptno and job with , seperating them.
    select ename, deptno || ',' || job from emp;
    
  17. Display employee name and year in which employee joined.
    select ename, to_char(hiredate,'yyyy') from emp;
    
  18. Display employee name and hiredate in the format hrs,day,month.
    select  ename, to_char(hiredate,'hh24, day, month') from emp;
    
  19. Change the hire date of employee 200 to same date but time should be 10:30 a:m.
    update emp set hiredate=to_date(to_char(hiredate,'dd-mm-yy')||'10:30','dd-mm-yyhh24:MI') where empno =200;
    
  20. Display employees who joined in the current year.
    select last_name from employees where to_char(sysdate,'yyyy')=to_char(hire_date,'yyyy')
    
  21. Modify price column of the title to include a constraint which ensures price>=0
    alter table titles modify ( price number(5) constraint titles_price_chk check ( price >= 0 ) );
    
  22. Include character s for checkconstraint of cover.
    alter table titles drop constraint titles_cover_chk;
    alter table titles modify (cover char(1) constraint titles_cover_chk check( cover in ('s','h','p','S','H','P')) );
    
  23. Make title not null.
    alter table titles modify ( title varchar(30) constraint titles_title_nn not null);
  24. Display author who wrote more than 3 books.
    select auid from titleauthors
    group by auid
    having count(*) > 3;
    
  25. Display author who wrote more than one book as the lead author.
    select auid from titleauthors where importance=1 group by auid having count(*)>1.
    
  26. Display subid,year,number of books published.
    select subid,to_char(pubdate,'yyyy'), count(*)
    from titles
    group by subid, to_char(pubdate,'yyyy');
    
  27. Display publisherID,subjectID and maximum price.
    select pubid,subid,max(price)
    from titles
    group by pubid,subid;
    
  28. Display subject and the date of most recent title.
    select subid,max(pubdate) from titles group by subid.
  29. Display year in which we published more than 2 books for subject Oracle.
    select to_char(pubdate,'yyyy')
    from  titles
    where subid ='ora'
    group by to_char(pubdate,'yyyy')
    having count(*) > 2;
    
  30. Display publishers who published more than 2 books in any single subject.
    select pubid
    from titles
    group by pubid,subid
    having count(*) > 2;
    
  31. Display month in which more than 2 books are published with cover of type hardbound.
    select to_char(pubdate,'month-yyyy')
    from titles
    where cover = 'h'
    group by to_char(pubdate,'month-yyyy')
    having count(*) > 2;
    
  32. Display title,subname for all titles of publisher 1.
    select title,sname
    from titles t, subjects s
    where t.subid = s.subid and  pubid = 1;
    
  33. Display title,year of publishing and publisher name for titles published in last 3 years.
    select title,to_char(pubdate,'yyyy'),pname
    from titles t, publishers p
    where t.pubid = p.pubid and months_between(sysdate,pubdate) <= 36;
    
  34. Display auid,year and number of titles written in each year.
    select auid, to_char(pubdate,'yyyy'), count(*)
    from titles t, titleauthors ta
    where  t.titleid = ta.titleid
    group by auid,to_char(pubdate,'yyyy');
    
  35. Display pubname,title of all titles written by author 103.
    select pname,title from titles t, publishers p
    where t.pubid = p.pubid and  titleid in
       ( select titleid from titleauthors where auid = 103);
    
  36. Display subname and average price of the books.
    select sname,avg(price)
    from subjects s, titles t
    where s.subid = t.subid
    group by sname;
    
  37. Display the difference between maximum price and minimum price for all books.
    select  max(price) - min(price) from titles;
    
  38. Display title and author name for only leading authors.
    select title, aname
    from titles t, authors a, titleauthors ta
    where  t.titleid = ta.titleid and a.auid = ta.auid and  importance = 1;
    
  39. Display authors who wrote a title in the current year.
    select aname
    from authors
    where auid in ( select auid from titleauthors where titleid in
                      ( select titleid from titles where to_char(sysdate,'yyyy') = to_char(pubdate,'yyyy') )
                  );
    
  40. Display titles published by the publisher whose name starts with 'w'.
    select title from titles
    where pubid in
        ( select pubid from publishers where pname like 'W%');
    
    
  41. Display publishers who published hardbound books.
    select pname
    from publishers
    where pubid in
       (  select pubid from titles where cover = 'h');
    
  42. Display the subjects for which we have more than 3 books published in any single year.
    select sname from subjects where subid in(select subid from titles group by subid having count(*)>3);
    
  43. Display the titles that are written by any author who wrote more than 2 books.
    select title
    from titles
    where titleid in
        ( select titleid from titleauthors
          where auid in
                   ( select auid
                     from titleauthors
                     group by auid
                     having count(*) > 1)
        );
    
    
  44. Display the publishers for whom more than 3 authors worked.
    select * from publishers
    where pubid in
        (select pubid from titles t,titleauthors ta where t.titleid=ta.titleid group by pubid having count(distinct auid)>3)
    
  45. Display the author who worked for a book with price more than 500.
    select aname
    from authors
    where auid in
       ( select auid from tilesauthors
         where titleid in
               (select titleid from titles where price > 500)
       );
    
  46. Change price of the title 1003 to average price of the titles.
    update titles set price = ( select avg(price) from titles) where titleid = 1003;
    
  47. Insert row into titleauthors where titleid is the maximum titleid,authorid is that of author 'stevens' with importance 1.
    insert into titleauthors values ( (select max(titleid) from titles),
        (select auid from authors where aname = 'Stevens'),1);
    
    
  48. Delete authors who have not written any title.
    delete from authors
    where auid not in ( select auid from titleauthors);
    

Queries with answers for 21-Mar-2006 Batch

  1. Display jobs that have minimum salary is set to null.
    select employee_id,job_id,salary from employees
    where salary is null;
  2. Display jobs where the title contains letter 's' twice
    select job_id,employee_id from employees where job_id like '%S%S%';
  3. Display the employees in the ascending order of jobs and descending order of salary
    select * from employees order by job_id,salary desc;
  4. Change the salary of employees with id=205 to 10000
    update employees set salary=10000 where employee_id=205;
  5. Insert a new department with department_id 300, name customersupport and remaining values as null
    insert into departments values(300,'cutsomer-support',null,null);
  6. Display the employeeid,hiredate and Experience of all the employees to the date
    select employee_id,hire_date,trunc(sysdate-hire_date)/365 Experience from employees;
  7. Display the employees who joined in the month of march of any year
    select employee_id,first_name,hire_date from employees where to_char(hire_date,'mon')='mar';
  8. Display the name,hiredate and the date on which first salary paid to the employee (assume-salary paid on the last day of the month)
    select first_name,hire_date,last_day(hire_date) FSPAIDON from employees;
    
  9. Display employees where the FirstName is bigger than the LastName
    select employee_id,first_name,last_name from employees
    where length(first_name)>length(last_name);
    
  10. Display employee name and experience in years where the name contains letter 'I' and 'T' in any order
    select first_name,trunc(sysdate-hire_date)Experience from employees
    where upper(first_name) like '%I%' and upper(first_name) like '%T%';
    
  11. Change Hiredate of employee 205 to 5th-jan-2006 at 10:30 a.m
    update employees set hire_date=to_date('5-JAN-06 10:30','DD-MON-YY HH24:MI')
    where employee_id=205;
    
  12. Display the title and authors for the title
    select title,aname  from titles t, authors a,titleauthors ta where t.titleid=ta.titleid and a.auid=ta.auid;
    
  13. Display title and subject name for books published in current year
    select title,sname from titles t,subjects s
    where t.subid=s.subid and to_char(t.pubdate,'yyyy')=to_char(sysdate,'yyyy');
    
  14. Display author name no.of titles written by author as lead author
    select aname,count(title) from titles t,authors a,
    titleauthors ta where ta.auid=a.auid and
    ta.titleid=t.titleid and importance=1 group by(aname);
    
  15. Display title that has no author details
    select title from titles t,titleauthors ta,authors a
    where t.titleid=ta.titleid and ta.auid=a.auid(+);
    
  16. Display publishers,year and no.of books published
    select pname,to_char(pubdate,'yyyy'),count(*)
    from titles t,publishers p where t.pubid=p.pubid
    group by pname,to_char(pubdate,'yyyy');
    
  17. Display subjects and no.of books published in the current year.
    select sname,to_char(pubdate,'yyyy'), count(*)
    from titles t,subjects s where s.subid=t.subid
    group by sname, to_char(pubdate,'yyyy');
    
  18. Display maximum price of all books.
    select title, max(price) from titles group by (title);
    
  19. Display month name and books with highest price of all books published in that month
    select to_char(pubdate,'month') Month,max(price) HighPrice from titles
    group by to_char(pubdate,'month');
    
  20. Display subjects for which we have more than 3 books which are hard bound.
    select sname,count(*) from subjects s,titles t
    where t.subid=s.subid and cover='P'
    group by sname having count(*)>3;
    
  21. Display the titleid for which we have got more than 2 authors
    select titleid from titleauthors ta,authors a
    where ta.auid=a.auid
    group by titleid having count(*)>2;
    
  22. Display titles published by publisher 'wrox' in the year 2004
    select title from titles t,publishers p
    where t.pubid=p.pubid
    and pname='wrox' and to_char(pubdate,'yyyy')=2005;
    
  23. Change email address of publisher 'wrox' from wroxus@yahoo.com to wroxus@usa.net
    update publishers set email='wroxus@usa.net'
    where pname='wrox';
    
  24. Display title,subjects,publisher name,lead author name
    select title,sname,pname,aname  LeadAuthor from titles t,subjects s,authors a,publishers p,titleauthors ta
    where t.subid=s.subid and t.pubid=p.pubid and t.titleid=ta.titleid and ta.auid=a.auid and importance=1;
    
  25. Display authorname for authors who wrote more than 1 title in a single year
    select aname from authors a,titleauthors ta,titles t
    where t.titleid=ta.titleid and ta.auid=a.auid group by(aname),to_char(pubdate,'yyyy')
    having count(*)>1;
    
  26. Display the titles published by 'wrox'
    select title from titles where pubid in
    (select pubid from publishers where pname='wrox');
    
  27. Display authors who wrote a book on oracle.
    select aname from authors a,titleauthors ta,titles t,subjects s
    where a.auid=ta.auid and ta.titleid=t.titleid and t.subid=s.subid and sname
    like '%or%';
    
  28. Display publishers who published books in the current year
    select pname from publishers where pubid in(select pubid from titles where to_char(pubdate,'yyyy')=to_char(sysdate,'yyyy'));
    
  29. Display titles that are published by 'wrox'
    select title from titles where pubid in (select pubid from publishers
    where pname='wrox');
    
  30. Display subject name,no.of books published where the price is >500
    select sname,count(title) from subjects s,titles t
    where t.subid=s.subid and price>500 groupby(sname);
    
  31. Display pubid,no.of books published where the title is written by more than one author
    select pubid,count(*) from titles where
    titleid in(select titleid from titleauthors group by titleid
    having count(*)>1)
    group by(pubid);
    
  32. Display the subjects for which no books were published in the current year
    select * from subjects where subid not in(select subid from titles where
    to_char(sysdate,'yyyy')=to_char(pubdate,'yyyy'));
    
  33. Display publishers who published a book in 2003 but not in 2004
    select pname from publishers p,titles t where
    t.pubid=p.pubid and to_char(pubdate,'yyyy')=2003 and to_char(pubdate,'yyyy')!=2004;
    
  34. Change the price of title-1003 to average price of "oracle books".
    update titles set price=(select avg(price)from subjects s,titles t
    where s.subid=t.subid and sname like '%ora%')
    where titleid=1003;
    
  35. Insert a row into titleauthors for title java.comp.ref and author 'Herbert Schild'
    insert into titleauthors values(
      (select titleid from titles where title = 'Java Comp. Ref'),
      (select auid from authors where aname = 'Herbert Schild'),1);
    
  36. Display publishers worked with 'Herbert Schild'
    select pname from publishers p,titles t,titleauthors ta, authors a
    where p.pubid=t.pubid and t.titleid=ta.titleid and ta.auid=a.auid and aname='herbert schildt' ;
    
  37. Display authors who have written at least one book as lead author.
    select aname from authors where auid in
    (select auid from titleauthors where importance=1);
    
  38. Display authors name who have written any title with author 'HERBERT SCHILD'
    select aname from authors where auid in
    (select auid from titleauthors where titleid in
      (select titleid from titleauthors where auid=
            (select auid from authors where aname='HERBERT SCHILD')
      )
    );
    
    
  39. Display publishers and no.of books published by them.
    select pname, count(*)
    from   publishers p, titles t
    where  p.pubid = t.pubid
    group  by pname;
    
  40. Display the subject for which we have more than 3 books written by more than one author.
    select subid from titles where titleid in
    (select titleid from titleauthors group by titleid having count(*)>1)
    group by subid having count(*)>1;
    
  41. Display no.of books published by each publisher on each subject
    select pubid,subid,count(*) from titles group by(pubid,subid) order by pubid,subid; 
  42. Display subjects for which no book was published in the current year
    select *from subjects where subid not in (select subid from titles
    where to_char(sysdate,'yyyy')=to_char(pubdate,'yyyy')); 
  43. Display the 2nd highest priced book from bookstroe
    select title,price from titles main
    where 1= (select count(*) from titles where price > main.price);