Claro! Eso eso eso, lo pruebo y te cuento.<br><br><div class="gmail_quote">2010/10/1 Leonardo Tadei - Pegasus Tech Supply <span dir="ltr">&lt;<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Entonces, una subquery con la forma:<br>
<div class="im"><br>
SELECT<br>
             <a href="http://news.id" target="_blank">news.id</a>,<br>
             tit,<br>
             cop,<br>
             des,<br>
             fecha,<br>
             ruta as img<br>
         FROM<br>
             news<br>
         LEFT JOIN<br>
             data<br>
</div>         ON  <a href="http://news.id" target="_blank">news.id</a> = (SELECT id_news FROM data WHERE <a href="http://news.id" target="_blank">news.id</a>=id_news<br>
LIMIT 0,1)<br>
<div class="im">                AND tipo = &#39;img&#39;<br>
         ORDER by<br>
             fecha DESC,<br>
             id DESC<br>
<br>
</div>        Es decir, hacés el LEFT JOIN relacionando <a href="http://news.id" target="_blank">news.id</a> con el resultado de<br>
una query que te devuelve solo un registro de data.<br>
        Puede ser que haga falta usar algún alias para desambiguar algún campo,<br>
pero la idea es esa...<br>
<br>
El vie, 01-10-2010 a las 09:01 -0300, Silverzero escribió:<br>
<div><div></div><div class="h5">&gt; Si, DISTINCT tambien lo había probado pero no me funcionó... :/<br>
&gt;<br>
&gt; 2010/10/1 Leonardo Tadei - Pegasus Tech Supply<br>
&gt; &lt;<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a>&gt;<br>
&gt;         Ahhh!!!<br>
&gt;<br>
&gt;         Entonces, sacale el LIMIT que te había dicho, y comenzá la<br>
&gt;         query con<br>
&gt;         SELECT DISTINCT ...<br>
&gt;<br>
&gt;                Sin embargo, tal vez esto no funcione porque en<br>
&gt;         realidad las filas no<br>
&gt;         estarán repetidas cuando haya distintas imágenes... probalo y<br>
&gt;         contanos,<br>
&gt;         y si no vamos a tener que armar una subquery que devuelva solo<br>
&gt;         un<br>
&gt;         registro por cada noticia.<br>
&gt;<br>
&gt;         El vie, 01-10-2010 a las 08:38 -0300, Silverzero escribió:<br>
&gt;<br>
&gt;         &gt; Si, pero en ese caso me lista una noticia sola, no?.<br>
&gt;         &gt; Yo quiero un listado completo de noticias por página, en<br>
&gt;         donde cada<br>
&gt;         &gt; noticia se muestra con ninguna (si no tuviese) o sólo una<br>
&gt;         imagen, para<br>
&gt;         &gt; que luego se pueda seleccionar una y ver todo el contenido<br>
&gt;         completo.<br>
&gt;         &gt;<br>
&gt;         &gt; 2010/10/1 Leonardo Tadei - Pegasus Tech Supply<br>
&gt;         &gt; &lt;<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a>&gt;<br>
&gt;         &gt;         Hola Carolina,<br>
&gt;         &gt;<br>
&gt;         &gt;                si solo querías la primer imagen, tu 1er<br>
&gt;         query estaba<br>
&gt;         &gt;         bien, solo que al<br>
&gt;         &gt;         final tenías que agregarle un LIMIT 0,1<br>
&gt;         &gt;<br>
&gt;         &gt;                El LIMIT es a toda la query...<br>
&gt;         &gt;<br>
&gt;         &gt;         El vie, 01-10-2010 a las 07:30 -0300, Silverzero<br>
&gt;         escribió:<br>
&gt;         &gt;<br>
&gt;         &gt;         &gt; No, solo una. Porque es para el listado de todas<br>
&gt;         las<br>
&gt;         &gt;         noticias, y<br>
&gt;         &gt;         &gt; queria que se mostrara cada una con una imagen de<br>
&gt;         todas las<br>
&gt;         &gt;         que<br>
&gt;         &gt;         &gt; tuviera asociadas (hubiera sido ideal la de menor<br>
&gt;         ID).<br>
&gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt; 2010/10/1 Leonardo Tadei - Pegasus Tech Supply<br>
&gt;         &gt;         &gt; &lt;<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a>&gt;<br>
&gt;         &gt;         &gt;         Pero esa query no te devuelve todas las<br>
&gt;         imágenes...<br>
&gt;         &gt;         no te<br>
&gt;         &gt;         &gt;         hacían falta<br>
&gt;         &gt;         &gt;         todas???<br>
&gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         El vie, 01-10-2010 a las 00:24 -0300,<br>
&gt;         Silverzero<br>
&gt;         &gt;         escribió:<br>
&gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt; Hola Leo,<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt; Gracias por la respuesta.<br>
&gt;         &gt;         &gt;         &gt; Lo arreglé así:<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;     $qry=&quot;SELECT<br>
&gt;         &gt;         &gt;         &gt;             <a href="http://news.id" target="_blank">news.id</a>,<br>
&gt;         &gt;         &gt;         &gt;             tit,<br>
&gt;         &gt;         &gt;         &gt;             cop,<br>
&gt;         &gt;         &gt;         &gt;             des,<br>
&gt;         &gt;         &gt;         &gt;             fecha,<br>
&gt;         &gt;         &gt;         &gt;             ruta as img<br>
&gt;         &gt;         &gt;         &gt;         FROM<br>
&gt;         &gt;         &gt;         &gt;             news<br>
&gt;         &gt;         &gt;         &gt;         LEFT JOIN<br>
&gt;         &gt;         &gt;         &gt;             data<br>
&gt;         &gt;         &gt;         &gt;         ON<br>
&gt;         &gt;         &gt;         &gt;             <a href="http://news.id" target="_blank">news.id</a> = id_news AND tipo =<br>
&gt;         &#39;img&#39;<br>
&gt;         &gt;         &gt;         &gt;         GROUP BY<br>
&gt;         &gt;         &gt;         &gt;             <a href="http://news.id" target="_blank">news.id</a><br>
&gt;         &gt;         &gt;         &gt;         ORDER by<br>
&gt;         &gt;         &gt;         &gt;             fecha DESC,<br>
&gt;         &gt;         &gt;         &gt;             id DESC&quot;;<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt; Lo único es que me elige una imagen a<br>
&gt;         criterio<br>
&gt;         &gt;         desconocido,<br>
&gt;         &gt;         &gt;         pero me da<br>
&gt;         &gt;         &gt;         &gt; la impresión que es una con el id<br>
&gt;         intermedio<br>
&gt;         &gt;         porque nunca es<br>
&gt;         &gt;         &gt;         la mayor<br>
&gt;         &gt;         &gt;         &gt; ni la menor.<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt; 2010/9/30 Leonardo Tadei - Pegasus Tech<br>
&gt;         Supply<br>
&gt;         &gt;         &gt;         &gt; &lt;<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a>&gt;<br>
&gt;         &gt;         &gt;         &gt;         Hola Carolina,<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;         El jue, 30-09-2010 a las 21:07<br>
&gt;         -0300,<br>
&gt;         &gt;         Silverzero<br>
&gt;         &gt;         &gt;         escribió:<br>
&gt;         &gt;         &gt;         &gt;         &gt; Hola tengo un problema con una<br>
&gt;         consulta<br>
&gt;         &gt;         a dos<br>
&gt;         &gt;         &gt;         tablas (que<br>
&gt;         &gt;         &gt;         &gt;         seguro es<br>
&gt;         &gt;         &gt;         &gt;         &gt; una pavada y yo no la veo), en<br>
&gt;         una tengo<br>
&gt;         &gt;         noticias<br>
&gt;         &gt;         &gt;         y en otra<br>
&gt;         &gt;         &gt;         &gt;         guardo<br>
&gt;         &gt;         &gt;         &gt;         &gt; archivos, videos e imagenes de<br>
&gt;         cada<br>
&gt;         &gt;         noticia, que<br>
&gt;         &gt;         &gt;         pueden ser,<br>
&gt;         &gt;         &gt;         &gt;         ninguna o<br>
&gt;         &gt;         &gt;         &gt;         &gt; más de una.<br>
&gt;         &gt;         &gt;         &gt;         &gt; Cuando listo las noticias<br>
&gt;         quiero que se<br>
&gt;         &gt;         vea UNA de<br>
&gt;         &gt;         &gt;         las fotos<br>
&gt;         &gt;         &gt;         &gt;         (la de ID<br>
&gt;         &gt;         &gt;         &gt;         &gt; menor), titulo, fecha,<br>
&gt;         &gt;         copete/desarrollo. Pero<br>
&gt;         &gt;         &gt;         cuando una<br>
&gt;         &gt;         &gt;         &gt;         noticia<br>
&gt;         &gt;         &gt;         &gt;         &gt; tiene más de una imagen me<br>
&gt;         lista la<br>
&gt;         &gt;         noticia<br>
&gt;         &gt;         &gt;         repetida tantas<br>
&gt;         &gt;         &gt;         &gt;         veces como<br>
&gt;         &gt;         &gt;         &gt;         &gt; imágenes haya asociadas.<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;                Esto está bien, y es como<br>
&gt;         se espera<br>
&gt;         &gt;         que<br>
&gt;         &gt;         &gt;         funcione una<br>
&gt;         &gt;         &gt;         &gt;         query: creciendo<br>
&gt;         &gt;         &gt;         &gt;         &quot;para abajo&quot; con tantos<br>
&gt;         registros como<br>
&gt;         &gt;         datos tenga<br>
&gt;         &gt;         &gt;         la<br>
&gt;         &gt;         &gt;         &gt;         respuesta.<br>
&gt;         &gt;         &gt;         &gt;                Por lo que planteás, es<br>
&gt;         como que<br>
&gt;         &gt;         esperás que<br>
&gt;         &gt;         &gt;         la<br>
&gt;         &gt;         &gt;         &gt;         respuesta &quot;se más<br>
&gt;         &gt;         &gt;         &gt;         ancha&quot;, es decir, tenga más<br>
&gt;         columnas, pero<br>
&gt;         &gt;         nunca vas<br>
&gt;         &gt;         &gt;         a tener<br>
&gt;         &gt;         &gt;         &gt;         más<br>
&gt;         &gt;         &gt;         &gt;         columnas que las que estés<br>
&gt;         proyectando.<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;                La solución a aplicar es<br>
&gt;         &gt;         programática: en la<br>
&gt;         &gt;         &gt;         primer<br>
&gt;         &gt;         &gt;         &gt;         iteración de la<br>
&gt;         &gt;         &gt;         &gt;         query, rescatá los datos de<br>
&gt;         News, y de la<br>
&gt;         &gt;         1ra y las<br>
&gt;         &gt;         &gt;         &gt;         siguientes, usá solo<br>
&gt;         &gt;         &gt;         &gt;         los datos proyectados de Data.<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;         &gt; Mi consulta original es<br>
&gt;         &gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;         &gt;     $qry=&quot;SELECT<br>
&gt;         &gt;         &gt;         &gt;         &gt;             <a href="http://news.id" target="_blank">news.id</a>,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             tit,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             cop,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             des,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             fecha,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             ruta as img<br>
&gt;         &gt;         &gt;         &gt;         &gt;         FROM<br>
&gt;         &gt;         &gt;         &gt;         &gt;             news<br>
&gt;         &gt;         &gt;         &gt;         &gt;         LEFT JOIN<br>
&gt;         &gt;         &gt;         &gt;         &gt;             data<br>
&gt;         &gt;         &gt;         &gt;         &gt;         ON<br>
&gt;         &gt;         &gt;         &gt;         &gt;             <a href="http://news.id" target="_blank">news.id</a> = id_news<br>
&gt;         AND tipo =<br>
&gt;         &gt;         &#39;img&#39;<br>
&gt;         &gt;         &gt;         &gt;         &gt;         ORDER by<br>
&gt;         &gt;         &gt;         &gt;         &gt;             fecha DESC,<br>
&gt;         &gt;         &gt;         &gt;         &gt;             id DESC&quot;;<br>
&gt;         &gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;         &gt; Había probado hacer una<br>
&gt;         consulta anidada<br>
&gt;         &gt;         en<br>
&gt;         &gt;         &gt;         reemplazo de<br>
&gt;         &gt;         &gt;         &gt;         ruta as img,<br>
&gt;         &gt;         &gt;         &gt;         &gt; por SELECT ruta FROM news,<br>
&gt;         data WHERE<br>
&gt;         &gt;         <a href="http://news.id" target="_blank">news.id</a> =<br>
&gt;         &gt;         &gt;         id_news AND<br>
&gt;         &gt;         &gt;         &gt;         tipo =<br>
&gt;         &gt;         &gt;         &gt;         &gt; &#39;img&#39; LIMIT 0,1, para que me<br>
&gt;         devuelva<br>
&gt;         &gt;         una sola,<br>
&gt;         &gt;         &gt;         pero se me<br>
&gt;         &gt;         &gt;         &gt;         repite la<br>
&gt;         &gt;         &gt;         &gt;         &gt; misma imagen en cada<br>
&gt;         noticia...<br>
&gt;         &gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;         &gt; Gracias<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;<br>
&gt;         &gt;         &gt;         &gt;                Por nada!<br>
&gt;         &gt;         &gt;         &gt;                (si se entiende)<br>
&gt;         &gt;<br>
&gt;         &gt;         &gt;<br>
&gt;         &gt;         --<br>
&gt;         &gt;<br>
&gt;         &gt;         Leonardo Tadei<br>
&gt;         &gt;         <a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a><br>
&gt;         &gt;         <a href="http://blog.pegasusnet.com.ar" target="_blank">http://blog.pegasusnet.com.ar</a><br>
&gt;         &gt;         Firma pública:<br>
&gt;         &gt;<br>
&gt;         <a href="http://www.pegasusnet.com.ar/LeonardoTadei-public.key" target="_blank">http://www.pegasusnet.com.ar/LeonardoTadei-public.key</a><br>
&gt;         &gt;<br>
&gt;         &gt;         _______________________________________________<br>
&gt;         &gt;         Php-avanzado mailing list<br>
&gt;         &gt;         <a href="mailto:Php-avanzado@pato2.fi.mdp.edu.ar">Php-avanzado@pato2.fi.mdp.edu.ar</a><br>
&gt;         &gt;<br>
&gt;         <a href="http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado" target="_blank">http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado</a><br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt; --<br>
&gt;         &gt; Carolina Derromediz<br>
&gt;         &gt; Cel. +54 223 5301599<br>
&gt;         &gt; _______________________________________________<br>
&gt;         &gt; Php-avanzado mailing list<br>
&gt;         &gt; <a href="mailto:Php-avanzado@pato2.fi.mdp.edu.ar">Php-avanzado@pato2.fi.mdp.edu.ar</a><br>
&gt;         &gt;<br>
&gt;         <a href="http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado" target="_blank">http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado</a><br>
&gt;         --<br>
&gt;<br>
&gt;         Leonardo Tadei<br>
&gt;         <a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a><br>
&gt;         <a href="http://blog.pegasusnet.com.ar" target="_blank">http://blog.pegasusnet.com.ar</a><br>
&gt;         Firma pública:<br>
&gt;         <a href="http://www.pegasusnet.com.ar/LeonardoTadei-public.key" target="_blank">http://www.pegasusnet.com.ar/LeonardoTadei-public.key</a><br>
&gt;<br>
&gt;         _______________________________________________<br>
&gt;         Php-avanzado mailing list<br>
&gt;         <a href="mailto:Php-avanzado@pato2.fi.mdp.edu.ar">Php-avanzado@pato2.fi.mdp.edu.ar</a><br>
&gt;         <a href="http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado" target="_blank">http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Carolina Derromediz<br>
&gt; Cel. +54 223 5301599<br>
&gt; _______________________________________________<br>
&gt; Php-avanzado mailing list<br>
&gt; <a href="mailto:Php-avanzado@pato2.fi.mdp.edu.ar">Php-avanzado@pato2.fi.mdp.edu.ar</a><br>
&gt; <a href="http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado" target="_blank">http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado</a><br>
--<br>
<br>
<br>
Leonardo Tadei<br>
<a href="mailto:leonardot@pegasusnet.com.ar">leonardot@pegasusnet.com.ar</a><br>
</div></div>Pegasus Tech Supply<br>
Tel: (+54)(+223) 471-2880<br>
La Salle 1131 - Mar del Plata - Argentina<br>
<a href="http://www.pegasusnet.com.ar" target="_blank">http://www.pegasusnet.com.ar</a> / <a href="http://blog.pegasusnet.com.ar" target="_blank">http://blog.pegasusnet.com.ar</a><br>
<a href="http://www.prometeustech.com.ar" target="_blank">http://www.prometeustech.com.ar</a> / <a href="http://www.grupopegasus.com" target="_blank">http://www.grupopegasus.com</a><br>
<div><div></div><div class="h5">Firma pública: <a href="http://www.pegasusnet.com.ar/LeonardoTadei-public.key" target="_blank">http://www.pegasusnet.com.ar/LeonardoTadei-public.key</a><br>
<br>
<br>
_______________________________________________<br>
Php-avanzado mailing list<br>
<a href="mailto:Php-avanzado@pato2.fi.mdp.edu.ar">Php-avanzado@pato2.fi.mdp.edu.ar</a><br>
<a href="http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado" target="_blank">http://www3.fi.mdp.edu.ar/cgi-bin/mailman/listinfo/php-avanzado</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Carolina Derromediz<br>Cel. +54 223 5301599<br>