Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danimohamadnejad's avatar

how to get multi lists together using one query?

hello

I am working on ecommerce website with laravel. I want to display most wished for, top rated and best seller products in category page.

is it possible to grab them all using one query or should I use three different queries what is best practice?

please explain

thank you

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

If you want to retain WHY they are in the list, then keep it as three queries so that you can list the results separately. Note that this may result in an item being in more than one list, for instance, top rated and most wished for.

If you want one result set where the members are either wished for, top rated or best seller then you might be able to use one query, depending on how those attributes are determined. This will be one list though and you won't know why an item is on the list.

1 like
danimohamadnejad's avatar

You are right I think I should use three different queries since conditions are totaly diffrenent and some of them are calculated through relations but my main concern is if this is true and database wont harm when number of people increase?

Snapey's avatar

So if the number of visitors increases, yet the lists are fairly stable, then cache the results of the three queries and only update them every few hours (for instance)

Please or to participate in this conversation.