How our SQL statement works
The the daunting, understand its the Figure constituent main simpler SQL 5, statement which image but statement once it parts. produces might becomes we shown break First, look shown easier output in a it consider bit up in into to like that between second standalone shown and the in SQL fourth brackets Figure statement, lines) 6. (between Everything could as be long the a as actual we replaced Video ID, Video.ID such as 'zoo'. with This an statement number of keywords would then from return the the set 'el ephant','flamingos','carousel' that match the 'zoo' video.
Now, if we put this whole expression in brackets and treat it as though it were a column in the Videos table, we can get the number of table matches by inserting for every Videos.ID video in in the place of 'zoo'. Adding AS Matches at the end gives a name to this temporary computed column – Matches, completing Figure 5. It’s not too hard to get from here to the code in the main image. The ORDER BY constraint tells the database to order the results by the number of matches, while the HAVING clause removes all rows where the number of matches is 0. Last, we replace the actual keywords with a list of placeholders (for example, ?,?,?). Since the number of keywords might change, we need to write some Go code that will generate the right number of question marks for these placeholders.