lundi 27 avril 2015

How do I get multiple values from a table in SQLite?

I have three tables:

authors
idname
1 Albert
2Bobby
3  Carl  
4  Dan  

authors_musicals
rowidauthor_idmusical_id
   1           1               1        
   2           2               1        
   3           1               2        
   4           1               3        

musicals
id       title      year
1  Brigadoon  1947
2My Fair Lady1956
3  Oklahoma! 1943
4   Camelot    1960

I need to get all the titles belonging to Albert (his id (1) from authors corresponds to musical_id (1, 2, 3) in authors_musicals which each correspond to title (Brigadoon, My Fair Lady, Oklahoma!) in musicals). I thought the following would work:

SELECT title FROM musicals WHERE id=(SELECT musical_id FROM authors_musicals WHERE author_id=(SELECT id FROM authors WHERE name="Albert"));

This only gives me the first listing. How can I get all three and since these tables are linked, is there a simpler way of getting what I want?

Aucun commentaire:

Enregistrer un commentaire