problem description
for example, there is an information table in mysql, each piece of data contains name and categoryId, and a table of category names, including categoryId and categoryName.
now there is an interface requirement to return the first N pieces of data under all categories, probably in this form
[
{
"categoryId":1001,
"data":[
{
"name":"test1"
},
{
"name":"test2"
}
]
},
{
"categoryId":1002,
"data":[
{
"name":"test3"
},
{
"name":"test4"
}
]
}
]
because the number of categories is not fixed, each category may have to access the database many times at a time. The current practice is to write a complex sql to check them all at once, and it can also be done. But I am afraid that the performance of sql cannot be guaranteed if there is a large amount of data in the future. Is there any other more general method that can be used for reference?