In my hobby DB, I made a query the other night to look for Dramas where two genres were either not present at all, or had a lower priority, excluding all Dramas from a certain country. This is the SQL generated by the Base GUI
SELECT "tdramas"."title",
"tcountries"."country",
"tdramas"."score",
"tstatus"."status",
"tgenre"."genre",
"tdrama-genre"."priority"
FROM "tdramas",
"tcountries",
"tstatus",
"tdrama-genre",
"tgenre"
WHERE "tdramas"."country" = "tcountries"."country-id"
AND "tdramas"."status" = "tstatus"."status-id"
AND "tdrama-genre"."drama-id" = "tdramas"."id"
AND "tdrama-genre"."genre-id" = "tgenre"."id"
AND ( "tdramas"."score" > 8
AND "tstatus"."status" = 'completed'
AND "tdrama-genre"."priority" > 2
AND "tcountries"."country-id" <> 4
AND ( "tdrama-genre"."genre-id" = 21
OR "tdrama-genre"."genre-id" = 22 )
OR "tdramas"."score" > 8
AND "tstatus"."status" = 'completed'
AND "tcountries"."country-id" <> 4
AND "tdrama-genre"."genre-id" <> 21
OR "tdramas"."score" > 8
AND "tstatus"."status" = 'completed'
AND "tcountries"."country-id" <> 4
AND "tdrama-genre"."genre-id" <> 22 )
ORDER BY "tdramas"."score" DESC
It works reasonably well, as long as the Dramas have more than 2 genres associate with them. So if genre 21 or 22 is priority 3 or 4, then they show up properly. If, though, the Dramas has fewer than 3 genres associated with, then Dramas with 21 or 22 listed in priority 1 or 2 still show up. As the two genres inquestion are OFTEN the only 2 listed, this means the query’s usefulness is suboptimal. How do I exclude those Dramas with fewer than 3 Dramas where the selected genres appear as either priority 1 or 2?
After running tyhe query, I went to the Base manual and spent quite a bit of time reading the sectionon queries trying to figure out the syntax I need, but it stumped me. THis query is one that will be useful in the next interation of my DB (espcially once I add parameters for choosing which genres to exclude, something I do know how to do) , so I’d be very grateful for help understanding what’s needed to achieve
“Include all Dramas from all countries except X where genres Y & Z are not present at all or are listed with priorities >2” including those Dramas with only 1 or 2 listed genre priorities.