Guest User

Untitled

a guest
Jan 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. use pubs
  2.  
  3. --cross join
  4. select titles.*, authors.*
  5. from titles, authors
  6.  
  7. select titles.*,authors.*
  8. from titles
  9. cross join authors
  10.  
  11. --geef de uitgevers met hun boeken
  12.  
  13. select *
  14. from publishers, titles
  15. where publishers.pub_id = titles.pub_id
  16. order by publishers.pub_id
  17. --of
  18.  
  19. select *
  20. from publishers
  21. join titles on publishers.pub_id = titles.pub_id
  22. order by publishers.pub_id
  23.  
  24. --geef de boeken met de authors
  25. select titles.title_id, titles.title, authors.au_id, authors.au_fname, authors.au_lname
  26. from titles
  27. join titleauthor on titles.title_id = titleauthor.title_id
  28. join authors on titleauthor.au_id = authors.au_id
  29. order by titles.title_id
  30.  
  31. --geef van de boeken met een prijs <20 de auteurs
  32.  
  33. select titles.title, titles.price, authors.au_fname, authors.au_lname
  34. from titles
  35. join titleauthor on titleauthor.title_id = titles.title_id
  36. join authors on titleauthor.au_id = authors.au_id
  37. where titles.price < 20
  38. order by titles.title_id
  39.  
  40. --geef alle uitgevers met hun boeken
  41.  
  42. select *
  43. from publishers
  44. left join titles on publishers.pub_id = titles.pub_id
  45. order by publishers.pub_id
  46.  
  47. --of
  48.  
  49. select *
  50. from titles
  51. right join publishers on publishers.pub_id = titles.pub_id
  52. order by publishers.pub_id
  53.  
  54. -- geef alle boeken vand e auteurs
  55.  
  56. select titles.title_id, titles.title, authors.au_id, authors.au_fname, authors.au_lname
  57. from titles
  58. left join titleauthor on titles.title_id = titleauthor.title_id
  59. left join authors on titleauthor.au_id = authors.au_id
  60. order by titles.title_id
  61.  
  62. --geef voor elke uitgeverij de werknemers รนmet hun jobbeschrijving
  63.  
  64. select publishers.pub_id, publishers.pub_name, employee.emp_id, employee.fname, employee.lname, jobs.job_id, jobs.job_desc
  65. from publishers
  66. left join employee on publishers.pub_id = employee.pub_id
  67. left join jobs on employee.job_id = jobs.job_id
  68. order by publishers.pub_id, employee.emp_id
  69. -- geef alle boeken met de winkels waar het boek wordt aangeboden
  70. select titles.title_id, titles.title, stores.stor_id, stores.stor_name
  71. from titles
  72. join sales on titles.title_id = sales.title_id
  73. join stores on sales.stor_id = stores.stor_id
  74. order by titles.title_id
  75.  
  76. -- geef de auteurs met een naamgenoot
  77. select *
  78. from authors a1
  79. join authors a2 on a1.au_lname = a2.au_lname and a1.au_id != a2.au_id
  80.  
  81.  
  82. use Family
  83.  
  84. --geef de kinderen van audrey halloway
  85. select *
  86. from Person p
  87. join Person pm on p.MotherID = pm.PersonID
  88. where pm.LastName = 'Halloway' and pm.FirstName = 'Audry'
  89. order by p.PersonID
  90.  
  91.  
  92. -- geef de moeder en de vader van elke persoon
  93.  
  94. select p.PersonID, p.FirstName, p.LastName,pm.PersonID, pm.FirstName, pm.LastName,pf.PersonID, pf.FirstName, pf.LastName
  95. from Person p
  96. left join Person pm on p.MotherID = pm.PersonID
  97. left join Person pf on p.FatherID = pm.PersonID
  98. order by p.PersonID
  99.  
  100. use pubs
  101. --geef de boeken met dezelfde prijs als de prijs van het boek 'straight talk about computers'
  102.  
  103. select *
  104. from titles
  105. where price = (select price
  106. from titles
  107. where titles.title = 'Straight talk about computers')
  108.  
  109. --geef de uitgevers die boeken van het type business uitgeven
  110. select publishers.*, titles.title_id, titles.title, titles.pub_id
  111. from publishers
  112. join titles on publishers.pub_id = titles.pub_id
  113. where titles.type = 'business'
  114. order by publishers.pub_id
  115.  
  116. --of
  117. select publishers.*
  118. from publishers
  119. where pub_id IN ( select pub_id
  120. from titles
  121. where type ='business')
  122. --geef de uitgervers die geen boeken van het type business uitgeven
  123.  
  124. select publishers.*
  125. from publishers
  126. where pub_id not IN ( select pub_id
  127. from titles
  128. where type ='business')
Add Comment
Please, Sign In to add comment