sandrulis Posted March 30, 2016 Report Share Posted March 30, 2016 Sveiki, ir divas tabulas posts: id, title, time 1, nosaukums 1, 12345 2, nosaukums 2, 12346 3, nosaukums 3, 12347 4, nosaukums 4, 12348 comments: id, post_id, comment, time 1, 2, comment 1, 12348 2, 2, comment 2, 12350 3, 3, comment 3, 12352 4, 1, comment 4, 12353 5, 3, comment 5, 12354 Kā man jānorādas mysql, lai rādītu rezultāti no posts, bet rādītu by time no abām tabulām, ja tipa postam ir jauns komentārs viņš viņu rāda kā pēdējo, kaut arī ir jaunāki posti. "SELECT p.id,p.title,p.time FROM posts AS p LEFT JOIN comments AS c ON c.post_id = p.id GROUP BY p.id ORDER BY p.time DESC" "ORDER BY p.time DESC" šajā vietā jāiemet kautkā ja (c.time > p.time ? c.time : p.time) Ceru, ka sapratāt domu Quote Link to comment Share on other sites More sharing options...
Blitz Posted March 30, 2016 Report Share Posted March 30, 2016 ORDER BY c.time DESC, p.time DESC sortēs vienmēr pēc jaunāka komentāra, ja nav postam komentāru tad sortēs pēc posta time Quote Link to comment Share on other sites More sharing options...
sandrulis Posted March 31, 2016 Author Report Share Posted March 31, 2016 (edited) paldies Edited March 31, 2016 by sandrulis Quote Link to comment Share on other sites More sharing options...
sandrulis Posted July 19, 2016 Author Report Share Posted July 19, 2016 sveiki, tomēr īsti nestrādā, strādāja pāri komentārus, bet pēc pāris komentāru ievadīšanas ORDER taisa tikai pēc p.time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.