I have 3 tables in MySQL.
excel - is the table where I store site-name, and side-id analys_result - is the table where I store keywords of sites, it has keyword, id of the category, id of site. categories - contain name and id of category
Here are screenshot's of tables, and what I need to retrieve:
Excel table
analys_result table
Result
Using just sql, the best you can get is:
select e.id, e.url, c.CategoryName, a.Keywords, count=sum(a.count)
from excel e, categories c, analys_results a
where e.id = a.websiteid
and a.categoryid = c.id
group by e.id, e.url, c.CategoryName, a.keywords
order by e.id, e.url, c.CategoryName, a.keywords
This will get you the correct data, but the grouping fields (id, url, categoryname) will show on every row in the result set (not ONCE per group), and making the query work that way using complicated SQL is NOT recommended. Let the database give you the data, and let the UI or Reporting Tool you are using determine how you want to display the results.