Show the three best evaluated vehicles in a table

1

I'm doing a site for the course, but I have a problem. I opted to use two tables, one for the "ratings", and another for the "vehicles". I would then like to select the 3 most valued vehicles from the table, and show it on the main page.

Ratings table: link

"Vehicle" table: link

Note: The table id 'classifications' is the same as the id of the other table.

    
asked by anonymous 01.05.2018 / 02:40

2 answers

1

test ai:

select vec.nome, classic.nome from veiculos as vec
inner join classificacoes as classic
on classic.id_veiculos = vec.id
where classic.estrelas > 3
order by classic.estrelas asc

Unfortunately, I can not access my database at this time, but this should resolve. Taking into consideration that the relevant number of stars is greater than 3.

    
01.05.2018 / 03:26
0

For the query return only the 3 best evaluated vehicles:

select * from classificacoes order by estrelas desc limit 3

Using join between tables would look like this:

select * from classificacoes c, veiculos v
where c.id_veiculo = v.id
order by c.estrelas desc limit 3

link

    
01.05.2018 / 04:14