Advertisement
4doorsmorehories

Dbms JOIN Opn

Jan 2nd, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.58 KB | Source Code | 0 0
  1. SQL> create table exp7book(bid int, title varchar(20), author varchar(20), status varchar(10));
  2.  
  3. Table created.
  4.  
  5. SQL> desc exp7book;
  6.  Name                      Null?    Type
  7.  ----------------------------------------- -------- ----------------------------
  8.  BID                            NUMBER(38)
  9.  TITLE                          VARCHAR2(20)
  10.  AUTHOR                         VARCHAR2(20)
  11.  STATUS                         VARCHAR2(10)
  12.  
  13. SQL> insert into exp7book values(101,'Fasting Feasting','Anitha Desai','Issued');
  14.  
  15. 1 row created.
  16.  
  17. SQL> insert into exp7book values(102,'Untouchable','Mukulraj Anand','Not Issued');
  18.  
  19. 1 row created.
  20.  
  21. SQL> insert into exp7book values(103,'Zahir','Paulo Coelo','Not Issued');
  22.  
  23. 1 row created.
  24.  
  25. SQL> insert into exp7book values(104,'Ancient Promises','Jayasree Misra','Issued');
  26.  
  27. 1 row created.
  28.  
  29. SQL> insert into exp7book values(105,'I Dare','Kiran Bedi','Issued');
  30.  
  31. 1 row created.
  32.  
  33. SQL> select * from exp7book;
  34.  
  35.        BID TITLE        AUTHOR           STATUS
  36. ---------- -------------------- -------------------- ----------
  37.        101 Fasting Feasting Anitha Desai         Issued
  38.        102 Untouchable      Mukulraj Anand       Not Issued
  39.        103 Zahir        Paulo Coelo      Not Issued
  40.        104 Ancient Promises Jayasree Misra       Issued
  41.        105 I Dare       Kiran Bedi       Issued
  42.  
  43. SQL> create table exp7bissued(bid int, uid int, issuedate date);
  44. create table exp7bissued(bid int, uid int, issuedate date)
  45.                                   *
  46. ERROR at line 1:
  47. ORA-00904: : invalid identifier
  48.  
  49.  
  50. SQL> create table exp7bissued(bid int,uid int,issuedate date);
  51. create table exp7bissued(bid int,uid int,issuedate date)
  52.                                  *
  53. ERROR at line 1:
  54. ORA-00904: : invalid identifier
  55.  
  56.  
  57. SQL> create table exp7bissued(bid int, U_id int, issuedate date);
  58.  
  59. Table created.
  60.  
  61. SQL> desc exp7bissued;
  62.  Name                      Null?    Type
  63.  ----------------------------------------- -------- ----------------------------
  64.  BID                            NUMBER(38)
  65.  U_ID                           NUMBER(38)
  66.  ISSUEDATE                      DATE
  67.  
  68. SQL> insert into exp7bissued values(101,32,'12-06-05');
  69.  
  70. 1 row created.
  71.  
  72. SQL> insert into exp7bissued values(104,67,'30-06-05');
  73.  
  74. 1 row created.
  75.  
  76. SQL> insert into exp7bissued values(105,67,'10-07-05');
  77.  
  78. 1 row created.
  79.  
  80. SQL> select * from exp7bissued;
  81.  
  82.        BID   U_ID ISSUEDAT
  83. ---------- ---------- --------
  84.        101     32 12-06-05
  85.        104     67 30-06-05
  86.        105     67 10-07-05
  87.  
  88. SQL> delete from exp7bissued where bid=101;
  89.  
  90. 1 row deleted.
  91.  
  92. SQL> delete from xp7bissued where bid=104;
  93. delete from xp7bissued where bid=104
  94.             *
  95. ERROR at line 1:
  96. ORA-00942: table or view does not exist
  97.  
  98.  
  99. SQL> delete from exp7bissued where bid=104;
  100.  
  101. 1 row deleted.
  102.  
  103. SQL> delete from exp7bissued where bid=105;
  104.  
  105. 1 row deleted.
  106.  
  107. SQL> insert into exp7bissued values(101,32,'');
  108.  
  109. 1 row created.
  110.  
  111. SQL> insert into exp7bissued(issuedate) values(STR_TO_DATE("09-Sep-2014","%d-%b-%Y")) where bid=101;
  112. insert into exp7bissued(issuedate) values(STR_TO_DATE("09-Sep-2014","%d-%b-%Y")) where bid=101
  113.                                                                                  *
  114. ERROR at line 1:
  115. ORA-00933: SQL command not properly ended
  116.  
  117.  
  118. SQL> insert into exp7bissued(issuedate) values(STR_TO_DATE("09-Sep-2014","%d-%b-%Y"));
  119. insert into exp7bissued(issuedate) values(STR_TO_DATE("09-Sep-2014","%d-%b-%Y"))
  120.                                           *
  121. ERROR at line 1:
  122. ORA-00904: "STR_TO_DATE": invalid identifier
  123.  
  124.  
  125. SQL> insert into exp7bissued values(101,32,'12-june-05');
  126.  
  127. 1 row created.
  128.  
  129. SQL> select * from exp7bissued;
  130.  
  131.        BID   U_ID ISSUEDAT
  132. ---------- ---------- --------
  133.        101     32
  134.        101     32 12-06-05
  135.  
  136. SQL> delete from exp7bissued where bid=101;
  137.  
  138. 2 rows deleted.
  139.  
  140. SQL> insert into exp7bissued values(101,32,'12-06-05');
  141.  
  142. 1 row created.
  143.  
  144. SQL> insert into exp7bissued values(104,67,'30-06-05');
  145.  
  146. 1 row created.
  147.  
  148. SQL> insert into exp7bissued values(105,67,'10-07-05');
  149.  
  150. 1 row created.
  151.  
  152. SQL> select * from exp7bissued;
  153.  
  154.        BID   U_ID ISSUEDAT
  155. ---------- ---------- --------
  156.        101     32 12-06-05
  157.        104     67 30-06-05
  158.        105     67 10-07-05
  159.  
  160. SQL> create table exp7buser(U_id int, Name varchar(10), course varchar(4), semester int, nob int);
  161.  
  162. Table created.
  163.  
  164. SQL> desc exp7buser;
  165.  Name                      Null?    Type
  166.  ----------------------------------------- -------- ----------------------------
  167.  U_ID                           NUMBER(38)
  168.  NAME                           VARCHAR2(10)
  169.  COURSE                         VARCHAR2(4)
  170.  SEMESTER                       NUMBER(38)
  171.  NOB                            NUMBER(38)
  172.  
  173. SQL> insert into exp7buser values(32,'Flozy','ECE',3,10);
  174.  
  175. 1 row created.
  176.  
  177. SQL> insert into exp7buser values(33,'Selina','ECE',4,0);
  178.  
  179. 1 row created.
  180.  
  181. SQL> insert into exp7buser values(34,'Ajith','CS',4,0);
  182.  
  183. 1 row created.
  184.  
  185. SQL> insert into exp7buser values(67,'Grace','IT',7,2);
  186.  
  187. 1 row created.
  188.  
  189. SQL> select * from exp7buser;
  190.  
  191.       U_ID NAME       COUR   SEMESTER        NOB
  192. ---------- ---------- ---- ---------- ----------
  193.     32 Flozy      ECE       3         10
  194.     33 Selina     ECE       4          0
  195.     34 Ajith      CS        4          0
  196.     67 Grace      IT        7          2
  197.  
  198. SQL> select * from exp7buser,exp7bissued where bid=101 and exp7bissued.U_id=exp7buser.U_id;
  199.  
  200.       U_ID NAME       COUR   SEMESTER        NOB    BID   U_ID ISSUEDAT
  201. ---------- ---------- ---- ---------- ---------- ---------- ---------- --------
  202.     32 Flozy      ECE       3         10    101     32 12-06-05
  203.  
  204. SQL> select Bid,Title,Author,Status from exp7book NATURAL JOIN exp7bissued where issuedate<'15-06-05';
  205.  
  206.        BID TITLE        AUTHOR           STATUS
  207. ---------- -------------------- -------------------- ----------
  208.        101 Fasting Feasting Anitha Desai         Issued
  209.  
  210. SQL> select * from exp7buser where Semester=4 and NOB>1;
  211.  
  212. no rows selected
  213.  
  214. SQL> select Title from exp7book NATURAL JOIN exp7bissued where issuedate='12-06-05';
  215.  
  216. TITLE
  217. --------------------
  218. Fasting Feasting
  219.  
  220. SQL> select Title from exp7book NATURAL JOIN exp7bissued where IssueDate='10-07-05';
  221.  
  222. TITLE
  223. --------------------
  224. I Dare
  225.  
  226. SQL> select * from exp7Buser where U_id in (select U_id from exp7Book INNER JOIN exp7bissued on exp7Book.Bid=exp7bissued.Bid where Title='Fasting Feasting');
  227.  
  228.       U_ID NAME       COUR   SEMESTER        NOB
  229. ---------- ---------- ---- ---------- ----------
  230.     32 Flozy      ECE       3         10
  231.  
  232. SQL> select Name from exp7Buser NATURAL JOIN exp7bissued where IssueDate LIKE'%07%';
  233.  
  234. NAME
  235. ----------
  236. Grace
  237.  
  238. SQL> select Name from exp7Buser NATURAL JOIN exp7bissued NATURAL JOIN exp7Book where Author='Kiran Bedi';
  239.  
  240. NAME
  241. ----------
  242. Grace
  243.  
  244. SQL> select Title from exp7Book NATURAL JOIN exp7bissued NATURAL JOIN exp7Buser where Name='Flozy';
  245.  
  246. TITLE
  247. --------------------
  248. Fasting Feasting
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement