3
In MYSQL I have two tables, product and product_photo.
In the product table_photo has a field that calls first that normally its value is 0. In the administrative system of the site there can be the marking of which the photo will be the first (main) and then this field first gets the value 1.
Table Product:
Table Product_photo:
When listing all products on the site, only one photo of each product is presented. And I wanted it to be just the photo in that field first is equal to 1.
I’ve been using the select:
SELECT * FROM produto
INNER JOIN produto_foto ON produto_foto.idproduto = produto.id
GROUP BY produto.id
ORDER BY produto.id DESC, primeira_foto.primeira DESC
Expected result:
chupeta - fotoX.jpg
caderno - fotoX.jpg
tesoura - foto.jpg (nesse caso não existiu marcação de qual é a foto 1, então pegaria o registro de menor ID da tabela Produto_Foto)
Try to illustrate your tables with data and try to add an expected result. Like the illustration of that question, it would make it a lot easier to help with an answer. http://answall.com/questions/131637/buscar-somente-o-menor-n%C3%Bamero-de-cada-letra/131640#131640
– Marconi
Thanks for the tip @Marconi, I edited here!
– caiocafardo
I improved it. Look how it turned out. I think that makes it better to understand @caiocafardo.
– Marconi