I'm trying to make a list of user related discussions.
Imagine, if you will:
posts
-------------------------------------------------------------------
ID | PID | FID | TITLE | USER
1 | 0 | 1 | Hello World | User 1
2 | 0 | 23 | Endangered Squirrels & How to Cook Them | Eddy
3 | 1 | 1 | Re: Hello World | Eddy
4 | 1 | 1 | Re: Hello World | Clark
5 | 0 | 3 | Any Vacation Suggestions? | Clark
6 | 5 | 3 | Re: Any Vacation Suggestions? | Eddy
7 | 5 | 3 | Re: Any Vacation Suggestions? | Clark
8 | 5 | 3 | Re: Any Vacation Suggestions? | Ellen
To show all of Eddy's posts I was using a query selecting posts with DISTINCT parents ids(pid) and thought it was working. I soon realized that 0 was only consider DISTINCT once and if he had created a new topic and not replied, it wasn't being listed if it wasn't his first.
So how do I get a list of ids with DISTINCT pid and pid != 0, and join it with a query of ids that have pid = 0 where the user = Eddy
This is the first question I've ever asked so forgive me if it's not perfect.
UPDATED WITH QUERY
I have since switched to using GROUP BY so I can fetch the post's id, but the issue is still the same
I was asked to provide my query. This is the one I'm using that only provides 1 row with pid as 0. I also updated my table layout above to show forum id, in the query below it only pulls topics from a list of public forums.
SELECT id, pid FROM posts WHERE fid IN (1,2,3) AND author = 'Eddy' GROUP BY pid ORDER BY IF(latest > timestamp, latest, timestamp) DESC LIMIT 1, 5;
thank you for any and all help.