Jump to content
php.lv forumi

grupeeshana


smarty

Recommended Posts

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

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

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

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 by smarty
Link to comment
Share on other sites

×
×
  • Create New...