smarty Posted June 21, 2005 Report Share Posted June 21, 2005 Veidoju savu galeriju un saskaaros ar nepatiikamu probleemu, atlasot konkreetam lietotaajam jaunaakos komentaarus. Ir 3 tabulas - comments(photoid), photos(userid,photoid) un users(userid). meegjinu shaadi SELECT p.photoid FROM photo AS p, comments AS c, users AS u WHERE u.userid=p.userid AND u.userid='66' AND c.photoid=p.photoid GROUP BY p.photoid ORDER by c.date DESC bet nesanaak sakaartot peec komentu laika (nav pareiza seciiba) nezin kaapeec tas group by sajauc to kaartoshanu ko izveido order by. bet man svariigi, lai paraada bildes peec to peedeejaa komenta datuma. Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2005 Report Share Posted June 21, 2005 A priekš kam tev tur vajag grupēt? Neredzu nekādu jēgu tam. Ja gribi vienkārši unikālos p.photoid vērtības dabūt tad jālieto DISTINCT: SELECT DISTINCT p.photoid FROM photo AS p, comments AS c, users AS u WHERE u.userid=p.userid AND u.userid='66' AND c.photoid=p.photoid ORDER by c.date DESC Nevajag lietot GROUP BY, kur to pavisam nevajag. Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 bet rezultaats ir identisks ieprieksheejam. tas distinct ejot cauri visaam atrastajaam usera bildeem panjem peedeejo bildi, kas atkaartojas (bet jaunaakaas komenteetaas ir pirmaas) Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2005 Report Share Posted June 21, 2005 A ko tad īsti tev vajag atlasīt? Konkrēta lietotāja visas bildes sakārtotas pēc pēdējā komentēšanas datuma? Man liekās, ka tieši to arī dara tas kverijs, vai tad ne? Link to comment Share on other sites More sharing options...
v3rb0 Posted June 21, 2005 Report Share Posted June 21, 2005 vispirms `izpildās` group by, pēc tam tikai sort. nav man laika pētīt un pārbaudīt, bet man liekas ka vajag salikto kveriju, ar pirmo saselectē un sasortē tā lai jaunākie būtu pirmie, un tikai tad ar otro sagrupē. select * from ( SELECT p.photoid FROM photo AS p, comments AS c, users AS u WHERE u.userid=p.userid AND u.userid='66' AND c.photoid=p.photoid ORDER by c.date DESC ) GROUP BY p.photoid Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 (edited) njaa bet sheit ir mysql 4.0.x un nau selektu no selekta :blink: es te taa papeetiiju un ieveroju ka shaadi SELECT c.date, c.text, p.photoid FROM photos AS p, comments AS c WHERE p.userid='2' AND c.photoid=p.photoid GROUP BY p.photoid ORDER by c.date DESC atrod vecaakos komentus un mistiski sakaarto (bet vajag atrast jaunaakos un sakaartot peec tiem) :huh: Edited June 21, 2005 by smarty Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2005 Report Share Posted June 21, 2005 Pateiksi varbūt ko vispār vajag atlasīt ar to selektu precīzi? Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 nu teiksim taa - atlasiit bildes un katrai jaunaako komentaaru. bildes sakartojot peec jaunaakaa komentaara datuma. pie tam bildes neatkaartojas. Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2005 Report Share Posted June 21, 2005 Ja vajag tikai jaunāko (vienu) komentāru, tad bez subselekta neiztikt (nu ja negrib izmantot papildus temporary tabulas), ja grib vienā selektā to visu. Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 ok, bet bez jaunaakaa komenta? nu taa vienkaarshi, tikai sakaartojot peec taa komenta datuma? ai.. laikam shaadi nesanaaks.. :( Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 bljaaviens, shaadi viss straadaa :) SELECT MAX(c.date) as laiks, p.photoid FROM photos AS p, comments AS c WHERE p.userid='66' AND c.photoid=p.photoid GROUP BY p.photoid ORDER by laiks DESC Link to comment Share on other sites More sharing options...
bubu Posted June 21, 2005 Report Share Posted June 21, 2005 (edited) Nu jā, grupējot un pielietojot agregātfju tā var darīt. Komentāru gan tu diez vai šādi dabūsi, tb kādu citu kolonnu no tās comments tabulas. Edited June 21, 2005 by bubu Link to comment Share on other sites More sharing options...
smarty Posted June 21, 2005 Author Report Share Posted June 21, 2005 viss kaartiibaa komentaars te nebija svariigs Link to comment Share on other sites More sharing options...
Recommended Posts