• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 15 páginas
Examen

Databases - Basic SQL iSubmit Exam with Answers

Document preview thumbnail
Vista previa 2 fuera de 15 páginas

Basic SQL syntax questions with answers for the course Databases, BSc AI.

Vista previa del contenido

Basic SQL syntax
The first names of all students
select first
from Students

The first names of all students living in Springfield
select first
from Students
where address = 'Springfield'

Last names of all students with first name George
select last
from Students
where first = 'George'

select first
from Students S
where S.last = 'Orwell'

Combining Students and Results
select *
from Students as S, Results as R
where S.sid = R.sid -- join condition

Joins of multiple tables
The results of George Orwell
select first, last, category, number, points
from Students as S, Results as R
where S.sid = R.sid -- join condition
and first = 'George' and last = 'Orwell'

Joining three tables: all results of George Orwell
select S.first, S.last, E.category, E.number, R.points, E.maxPoints
from Students S, Results R, Exercises E
where S.sid = R.sid -- join condition for S-R
and R.category = E.category and R.number = E.number -- join condition for R-E
and S.first = 'George' and S.last = 'Orwell'

Persons who take classes
select P.name, C.kind
from Persons P, Classes C, TakesClasses T
where P.id = T.person_id
and C.id = T.class_id




1

, All students that have 9 points in homework 1 and 2
select S.first, S.last
from Students S, Results R1, Results R2
where S.sid = R1.sid
and S.sid = R2.sid
and R1.category = 'homework' AND R1.number = 1
and R2.category = 'homework' AND R2.number = 2
and R1.points >= 9 AND R2.points >= 9

Persons who like someone with blue eyes
select distinct PA.name
from Persons PA, Persons PB, Likes L
where PA.id = L.personA_id and PB.id = L.personB_id
and PB.eyeColor = "blue"

Persons who like at least two people with green eyes
select distinct PA.name
from Persons PA, Persons PB, Likes L
where PA.id = L.personA_id and PB.id = L.personB_id
and PB.eyeColor = "green"
group by PA.name
having count(*) >= 2

Men that play soccer with a female player
select distinct P.name
from Persons P, Persons PA, Persons PB, SportTogether S
where PA.id = S.personA_id and PB.id = S.personB_id
and (PA.name = P.name or PB.name = P.name)
and (P.gender = 'male' and PA.gender <> PB.gender)
and S.sport = 'soccer'

Last names without duplicates
select distinct last
from Students

(Inner) join
SELECT A.name, B.name
FROM TableA A JOIN TableB B
ON A.id = B.id

Left (outer) join
SELECT A.name, B.name
FROM TableA A LEFT JOIN TableB B
ON A.id = B.id


2

Información del documento

Estudio
Subido en
1 de enero de 2025
Número de páginas
15
Escrito en
2020/2021
Tipo
Examen
Contiene
Preguntas y respuestas
$9.82

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Vendido
30
Seguidores
2
Artículos
38
Última venta
3 meses hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes