comunque prendo per buono che i due campi sono tutti e due testo.....![]()
1)
Prova a vedere se questa query ti soddisfa (se funziona poi aggiungi tu le varie condizioni)
2)(SELECT top 1 tb_foto.str_img, tb_gallery.str_gallery
FROM tb_gallery INNER JOIN tb_foto ON tb_gallery.str_gallery = tb_foto.str_gallery order by id_foto desc)
UNION
(SELECT top 1 tb_foto.str_img, tb_gallery.str_gallery
FROM tb_gallery INNER JOIN tb_foto ON tb_gallery.str_gallery = tb_foto.str_gallery where id_gallery not in
(SELECT top 1 tb_gallery.id_gallery
FROM tb_gallery INNER JOIN tb_foto ON tb_gallery.str_gallery = tb_foto.str_gallery order by id_foto desc)
order by id_foto desc)
Se mi posso permettere di darti un consiglio evita sempre di usare join su campi testo ma usale invece sui campi numerici (contatori)
Nel tuo caso la join ideale sarebbe stata tra
str_gallery (campo numerico contenente la chiave della tab tb_gallery a cui appartiene la foto)
id_gallery (campo chiave della tab tb_gallery)
![]()
fammi sapere se va

Rispondi quotando