From: | Gerard Samuel <gsam(at)trini0(dot)org> |
---|---|
To: | pgsql-php(at)postgresql(dot)org |
Subject: | Left Join SQL Help |
Date: | 2003-02-01 20:37:50 |
Message-ID: | 3E3C301E.2050005@trini0.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
Im trying to write a "Left Join" sql statement.
There are 4 tables in a similar structure to ->
[user table]
user_id - username
[user2 table]
uid - user_regdate
[post table]
post_id - poster_id
[posts_text table]
post_id - post_text
[whosonline table]
uid - session_id
This is the sql that Im using ->
SELECT u.user_id, u2.user_regdate, p.post_id, w.uid FROM posts p LEFT
JOIN posts_text pt ON p.post_id = pt.post_id LEFT JOIN users u ON
p.poster_id = u.user_id LEFT JOIN users2 u2 ON p.poster_id = u2.uid LEFT
JOIN whosonline w ON p.poster_id = w.uid WHERE topic_id =
'AFAdDFoAPjvgJNzj' ORDER BY post_time LIMIT 10 OFFSET 0;
If the whosonline table has more than one entry for "anonymous user" id
-1, the sql reports 5 rows.
The 2 last rows should just be one row.
user_id | user_regdate | post_id | uid
------------------+--------------+------------------+-----
1 | 1009861200 | a |
1 | 1009861200 | b |
1 | 1009861200 | c |
-1 | 0 | d | -1
-1 | 0 | d | -1
(5 rows)
Any help in this matter would be appreciated. Thanks.
--
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/
From | Date | Subject | |
---|---|---|---|
Next Message | Gerard Samuel | 2003-02-01 21:26:08 | Re: Left Join SQL Help |
Previous Message | Zak Greant | 2003-01-31 22:37:15 | Re: text editor |