dimanche 30 août 2015

How to get pairs from sqlite

I am a database and I am just playing with sqlite3 for a group project.

I have two tables that look something like this:

Table 1:

tv_show_id, tv_show_rating

Table 2:

tv_show_id, cast_id

Each tv_show has 1 unique id, but in table two there are multiple cast_ids for each tv_show

So we have something like this:

Table 1: 1234, 90 5678, 88

Table 2: 1234, "person 1" 1234, "person 2" 5678, "person 1" 5678, "person 3"

I want the following results: (person a, person b, # of shows together)

(person 1, person 2, 1) (person 1, person 3, 1) (person 2, person 1, 1) (person 2, person 3, 0) (person 3, person 1, 1) (person 3, person 2, 0)

How can i use JOINS to get these results?

THANK YOU!

Aucun commentaire:

Enregistrer un commentaire