Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
SELECT * FROM tablica WHERE DISTINCT IDkategorije

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
designCreaTor



Joined: 29 Sep 2005
Posts: 59
Location: Sarajevo, BA

PostPosted: 07.07.2011 21:09    Post subject: SELECT * FROM tablica WHERE DISTINCT IDkategorije Add user to your forum ignore list Reply with quote

jedno pitanje Smile

imam tablicu

ID tekst IDkategorije datum

Trebam da izlistam zadnjih 5 tekstova iz RAZLICITIH kategorija.

Znači nije problem izlistati DISTINCT kategorije,

ali meni trebaju SELECT * FROM tablica WHERE DISTINCT IDkategorije (naravno ovako ne radi)...

hvala Confused
Back to top
View user's profile Send private message MSN Messenger
Moebius



Joined: 26 Jan 2004
Posts: 245
Location: zagreb

PostPosted: 07.07.2011 22:37    Post subject: Add user to your forum ignore list Reply with quote

probaj (mysql):
Code:
select A.ID, A.tekst, A.IDkategorije, A.datum
from tablica A
where 5 > (select count(*) from tablica B
           where A.IDkategorije = B.IDkategorije and A.datum < B.datum)
and IDkategorije in (select distinct IDkategorije from tablica)
group by A.IDkategorije, A.ID order by A.IDkategorije
Back to top
View user's profile Send private message Visit poster's website
cindreta



Joined: 10 Dec 2004
Posts: 30

PostPosted: 08.07.2011 00:01    Post subject: Add user to your forum ignore list Reply with quote

Code:
SELECT id,tekst,IDkategorije,datum FROM tablica GROUP BY IDkategorije ORDER BY RAND() LIMIT 5


ovo će ti vratit 5 članaka sa unique kategorijama. nego nemoj koristit "*" i ak baš ne moraš nemoj ni ORDER BY RAND() radije to php-om rješi. al ovo je fast and dirty Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group