/*esercizio 1*/ SELECT LIBRI.codice, titolo, EDITORI.codice, nome FROM LIBRI JOIN EDITORI ON LIBRI.codice_editore=EDITORI.codice; SELECT LIBRI.codice, titolo, EDITORI.codice, nome FROM LIBRI, EDITORI WHERE LIBRI.codice_editore=EDITORI.codice; /*esercizio 2*/ SELECT titolo, prezzo FROM LIBRI JOIN EDITORI ON LIBRI.codice_editore=EDITORI.codice WHERE EDITORI.nome = 'Signet'; /*esercizio 3*/ SELECT titolo, LIBRI.codice FROM LIBRI, EDITORI WHERE LIBRI.codice_editore=EDITORI.codice and (EDITORI.nome = 'Bantam Books') AND (prezzo>10); /*esercizio 4*/ SELECT LIBRI.codice, titolo, num_copie_disponibili, 'es4' FROM LIBRI JOIN SCORTE NATURAL JOIN FILIALI ON LIBRI.codice=SCORTE.codice_libro WHERE FILIALI.numero_filiale=3; /*esercizio 5*/ SELECT titolo FROM LIBRI JOIN EDITORI ON LIBRI.codice_editore=EDITORI.codice WHERE tipo LIKE 'COM' AND (EDITORI.nome LIKE 'Best and Furrow'); /*esercizio 6*/ SELECT titolo FROM LIBRI JOIN HASCRITTO NATURAL JOIN AUTORI ON LIBRI.codice=HASCRITTO.codice_libro WHERE AUTORI.numero_autore=01; SELECT titolo FROM LIBRI, HASCRITTO, AUTORI WHERE LIBRI.codice=HASCRITTO.codice_libro and HASCRITTO.numero_autore= AUTORI.numero_autore and AUTORI.numero_autore=01; SELECT titolo FROM LIBRI WHERE codice IN (SELECT codice_libro FROM HASCRITTO where LIBRI.codice= HASCRITTO.codice_libro and HASCRITTO.numero_autore=01); /*esercizio 7*/ /* Traccia: Ripetere l'esercizio 4 utilizzando EXISTS nella formulazione*/ SELECT LIBRI.codice, titolo, num_copie_disponibili, numero_filiale FROM LIBRI NATURAL JOIN SCORTE WHERE exists (select * from FILIALI where SCORTE.numero_filiale= FILIALI.numero_filiale and LIBRI.codice= SCORTE.codice_libro and FILIALI.numero_filiale=3) order by LIBRI.codice; /*esercizio 8*/ SELECT titolo, LIBRI.codice FROM LIBRI JOIN SCORTE NATURAL JOIN FILIALI ON LIBRI.codice=SCORTE.codice_libro WHERE SCORTE.numero_filiale='2'; /*esercizio 9*/ SELECT F.CODICE_LIBRO, S.CODICE_LIBRO FROM SCORTE F, SCORTE S WHERE F.NUMERO_FILIALE = S.NUMERO_FILIALE AND F.CODICE_LIBRO5) UNION (SELECT LIBRI.CODICE, TITOLO FROM LIBRI,EDITORI WHERE LIBRI.codice_editore=EDITORI.CODICE AND CITTA= 'New York'); select distinct LIBRI.codice, LIBRI.titolo from LIBRI join EDITORI on LIBRI.codice_editore=EDITORI.codice where LIBRI.prezzo>5 or EDITORI.citta='New York'; /*esercizio 13 */ /*intersezione e differenza non sono supportate in MySQL*/ /*(SELECT CODICE,TITOLO FROM LIBRI WHERE PREZZO>5) EXCEPT (SELECT LIBRI.CODICE, TITOLO FROM LIBRI,EDITORI WHERE LIBRI.codice_editore=EDITORI.CODICE AND CITTA= 'New York');*/ /*(SELECT CODICE,TITOLO FROM LIBRI WHERE PREZZO>5) INTERSECT (SELECT LIBRI.CODICE, TITOLO FROM LIBRI,EDITORI WHERE LIBRI.codice_editore=EDITORI.CODICE AND CITTA<> 'New York');*/ select distinct LIBRI.codice, LIBRI.titolo from LIBRI join EDITORI on LIBRI.codice_editore=EDITORI.codice where LIBRI.prezzo>5 and EDITORI.citta<>'New York'; /*esercizio 14*/ SELECT TITOLO, CODICE_EDITORE FROM LIBRI WHERE PREZZO >ALL (SELECT PREZZO FROM LIBRI WHERE TIPO='HOR'); /*ESERCIZIO 15*/ SELECT TITOLO, CODICE_EDITORE FROM LIBRI WHERE PREZZO >ANY (SELECT PREZZO FROM LIBRI WHERE TIPO='HOR');