0
I am doing a project, where will allow you to register more than one image per product, this has been generating me a certain difficulty. I wanted to list the products that have image and only an image that same product.
Obviously there may be an easier way to do that
I’ve tried some ways that haven’t been giving the right result that I hope.
The closest to the final result was the one below, but duplicates the product that has more than one image
SELECT DISTINCT *, (SELECT qc_imagens.img_nome FROM qc_imagens
JOIN qc_produtos on qc_produtos.pro_id = qc_imagens.img_pro_id
WHERE qc_imagens.img_nome <> NULL AND qc_imagens.img_excluido = '0'
order by qc_imagens.img_id DESC
LIMIT 1) AS nome_img
FROM qc_produtos p
INNER JOIN qc_imagens img on img.img_pro_id = p.pro_id
INNER JOIN qc_categorias c ON p.pro_categoria = c.cate_id
WHERE pro_ativo = 1 AND img.img_excluido = '0'
Thanks in advance
It didn’t work, I don’t have the ER of this db, but that’s right N products --------------- 1 images A product can have n images
– gabrielfalieri
I edited the answer, but if it doesn’t work out, try this link tb: https://answall.com/questions/96756/como-selectr-apenas-1-registro-de-cada-id
– Kamehameha
Speak there, had even managed, but its much leaner form, I marked as solved, quarreled :) Had turned 2 subselect... an almost gambs
– gabrielfalieri