0

Can I create an inner join on free base that uses another query?

I tried to create a join between 2 querys:

The first, select all the artist that the genre is the same as nirvana without nirvana:

[{
  "id": null,
  "name": null,
  "name!=": "nirvana",
  "type": "/music/artist",
  "genre": [{
    "name|=": [
      "Punk rock",
      "Grunge",
      "Alternative rock",
      "Rock music",
      "Hardcore punk"
    ]
  }]
}]

the second, select all the genre of nirvana:

[{
  "name": "nirvana",
  "type": "/music/musical_group",
  "/music/artist/genre": []
}]

I want to create a query like this but it does not work.

[{
  "id": null,
  "name": null,
  "name!=": "nirvana",
  "type": "/music/artist",
  "genre": [{
    "name|=":
     [{
        "name": "nirvana",
        "type": "/music/musical_group",
        "/music/artist/genre": []
     }]
  }]
}]
ChrisM
  • 1,576
  • 6
  • 18
  • 29
royb
  • 693
  • 3
  • 9
  • 20

1 Answers1

1

I'm not sure why you need to do this all as one query. Since Nirvana's music spans a number of very popular genres your query will probably return thousands of results which will mean that you'll have to make multiple API requests to get all the results either way.

In any case, here's a MQL query that finds all the bands which have at least one music genre in common with Nirvana:

[{
  "id": null,
  "name": null,
  "/music/artist/genre": [{
    "id": null,
    "name": null,
    "!/music/artist/genre": {
      "id": "/m/0b1zz",
      "name": null
    }
  }]
}]

The exclamation mark in front of the 2nd genre property means that we want the inverse relationship ie. "music artists with this genre" instead of "music genres for this artist".

Note that I've used the MID (/m/0b1zz) to represent Nirvana. You shouldn't be using names to identify topics in a query since they're not unique. You want results for the Nirvana started by Kurt Cobain in 1987, not just any band named Nirvana.

Shawn Simister
  • 4,613
  • 1
  • 26
  • 31