PDA

View Full Version : select problem


zodehala
05-10-2008, 01:37 AM
how can i select username in user table where user have biggest dateline value in post table ?

http://img140.imageshack.us/img140/612/tableej1.jpg

oesxyl
05-10-2008, 04:21 AM
select u.username from user as u, post as p
where p.userid = u.userid order by p.dateline desc limit 0,1


regards

zodehala
05-10-2008, 10:40 AM
select u.username from user as u, post as p
where p.userid = u.userid order by p.dateline desc limit 0,1


regards

thanx for your reply

furthermore i wanna add a condition too . if parentid is 0 or NULL select least dateline value ?

oesxyl
05-10-2008, 05:01 PM
thanx for your reply

furthermore i wanna add a condition too . if parentid is 0 or NULL select least dateline value ?

make parentid not null when you create table and probably is a good idea to make it default 0

select u.username from user as u, post as p
where p.userid = u.userid and p.parent id = 0
order by p.dateline asc limit 0,1


but this don't work along with previous query from my post.

regards

zodehala
05-12-2008, 10:26 PM
i wanna do a forum

if parentid is 0 it is a thread (namely first reply) .if parentid isnot 0 it is a reply

how can list thread and parent id is 22 (but at the same time i wanna list first reply which parentid is 0



http://img105.imageshack.us/img105/772/phpqb3.jpg