The context is as follows:
- We have 3 tables: We'll call them A,B and C.
- A has a foreign key referencing table B, we'll call it "bId". The relationship is a ManyToOne. (One record in B can be linked to multiple ones in A, but each record in A is linked to exactly one in B)
- B has a foreign key referencing table C, we'll call it "cId". Same as before, the relationship is ManyToOne One record in C can be linked to multiple ones in B, but each record in B is linked to exactly one in C).
Now, the problem is as follows: Until now, to correlate information between these 3 tables I used a query of the form
A inner join B inner join C WHERE b.someField = 'x' AND a.otherField = 'y'
, and then processed the aggregated information using a programming language.
My question is, is it possible to limit the number of entries from the table C?
Let's say that C has a field called name, and I only want the data from the first 3 C values, alphabetically. A problem similar to mine seems to be the one answered here, but I don't see how to generalise the solution.
To be clear, I don't want to limit the number of records in general, just the ones from the third table.
CREATE
statements of the tables and/or other objects involved (paste the text, don't use images, don't link to external sites),INSERT
statements for sample data (dito) and the desired result with that sample data in tabular text format.