there are tables 'Content' and 'Rettig_Content', records are stored in the first one, and the second assessment of these records, you need to make a rating, in order to sort and display the first records with the highest rating - this is the amount / quantity

Tabls: Content: ------|-----------|------------------|--------|----------| id | title | description | img | datetime | ------|-----------|------------------|--------|----------| 1 | TEXT | TEXT | TEXT | DATETIME | ------|-----------|------------------|--------|----------| 2 | TEXT | TEXT | TEXT | DATETIME | ------|-----------|------------------|--------|----------| 3 | TEXT | TEXT | TEXT | DATETIME | ------|-----------|------------------|--------|----------| Rettig_Content: ------|-----------|------------------|--------| id | user_id | content_id | voice | ------|-----------|------------------|--------| 1 | 44566 | 1 | 5 | ------|-----------|------------------|--------| 2 | 23566 | 1 | 3 | ------|-----------|------------------|--------| 3 | 55566 | 1 | 3 | ------|-----------|------------------|--------| 4 | 44566 | 3 | 5 | ------|-----------|------------------|--------| 
  • I think you should specify what means with the "highest rating"? sort by average rating (arithmetic average)? or something else? - Batanichek
  • Yes, the arithmetic average - Kill Noise

1 answer 1

 select c.id,c.title,c.description,c.img,c.datetime, avg(r.voice) as rate from Content as c left join Rettig_Content as r on r.content_id=c.id group by c.id,c.title,c.description,c.img,c.datetime order by rate desc