samedi 26 mars 2016

Select minimum shared common data

Title might be a bit off, but I'll try to explain.

My example data looks like this:

door1 | key1
door1 | key2
door2 | key1
door2 | key2
door2 | key3
door3 | key1
door3 | key3
door4 | key2

Id like to select the least amount of keys needed to open all doors. In this case the output would be key1 for door1, door2 and door3, and key2 for door4.

Output:

key1
key2

I solved this programmatically but I feel as there should be a way to whip up a select to have the DB do this for me.

Aucun commentaire:

Enregistrer un commentaire