Hello,
Currently, I have a couple of queries that are taking a couple seconds to process and load the page and I was wondering if you could point me in the right direction to clean this up.
I have two tables that are being accessed over 2 queries right now.
This query grabs all the beer names for one brewery
Then I take those results and loop through them to also display some stats about the beer. (number reviews, average score etc.)
I was trying to use a JOIN like so, but as soon as I do, it limits the results to one row.
Is it possible to do what I am trying to do with one query? I assume it will cut my page load time down significantly if I can consolidate it.
Thank you
Currently, I have a couple of queries that are taking a couple seconds to process and load the page and I was wondering if you could point me in the right direction to clean this up.
I have two tables that are being accessed over 2 queries right now.
This query grabs all the beer names for one brewery
Code:
SELECT beer.beer_id,beer.beer_name
FROM beer
WHERE beer.brewery_id='some_id'
ORDER BY beer.beer
Then I take those results and loop through them to also display some stats about the beer. (number reviews, average score etc.)
Code:
foreach($result do this){
SELECT AVG(total) AS score, COUNT(beer_id) AS review_count ,MAX(total) AS high_score ,MIN(tot) AS low_score
FROM `ratings`
WHERE beer_id='".$row->beer_id."'
}
I was trying to use a JOIN like so, but as soon as I do, it limits the results to one row.
Code:
SELECT beer.beer_id,beer.beer_name,AVG(total)
FROM beer
JOIN ratings ON ratings.beer_id=beer.beer_id
WHERE beer.brewery_id='some_id'
ORDER BY beer.beer
Is it possible to do what I am trying to do with one query? I assume it will cut my page load time down significantly if I can consolidate it.
Thank you