I have a query which lists 10 different items in a database.
Within this query, i have a nested query which, for each of items 1-10 listed above, finds related subcategories in another table.
So ultimately, 11 queries occur. 1 to iterate through the major categories, and the other 10 to query and output for each of those categories.
Problem is, collectively, they output duplicated values.
Since it is done over 10 queries, i cant use DISTINCT, because even if the output is distinct within its own query, it is not distinct in the overall group.
So how can i make sure that i multiquery list like this is unique? Does js or php have a built in function that can do such?
Your code is not really scaleable. You’re already reaching large numbers of queries, imagine if you had 100 items…
Instead, consider creating a subquery within the original query, since this would allow you to only run one query and the MySQL engine can do all the crunch work more easily (since it knows what you’re actually asking for).
Make use of
JOINs if possible, and pay close attention to indexes. I can’t really help more without seeing some code, but this should help becauseDISTINCTwould suddenly be usable again.