The following join attempts to join Travel-Sample and Beer-Sample by a non-key field "country.
Select b.country COUNTRY, b.name BREWERY, a.name AIRLINE
From `travel-sample` a
Join `beer-sample` b On Keys (a.country)
Order By a.country, b.name;
While the query is processed it returns a null result string, which is incorrect.
The discussion of the “On Keys” clause with respect to its use in joins does state that the key being referenced should be the primary key of the table being joined, so I understand that this query will not work in its present form. My question: Is there any way in N1QL to execute this join correctly?
btw: I’m trying to catalog all of the places where N1QL is different from SQL, and in fact the above join could be successfully executed in generic SQL.
This pattern is currently not supported, but will be supported in Couchbase in the future. Can you share your N1QL vs. SQL catalog with us when it is ready?
On JOINs, we are incrementally adding to our JOIN support. In 4.0, the left keyspace had to contain the primary of the right table. In 4.1, we expanded the syntax to include the case where the right keyspace contains the primary of one of the left keyspaces.
Longer term, we should provide all the SQL JOIN functionality, while keeping the additional JSON support unique to N1QL.
Could you give an example for how to use this new JOIN capability of 4.1 (the case where the right keyspace contains the primary of one of the left keyspaces).
Also, does 4.1 also support NEST with the similar requirement on keys as above?
@geraldss Thanks for your follow up! I haven’t tried it yet, since I don’t have the enterprise edition (4.1). It will be one of the first things I try when it’s available as community edition (I’ve bookmarked your reply).