Page 1 of 1

Help with mySQL query

Posted: Fri Jul 25, 2003 7:24 am
by RFairey
I have built a simple forum using php and mySQL -

I have a boards table, a threads table, and a posts table to store the various parts of the forum. Each post/thread/board has an ID number - an autoincremented value used as primary key, and each post has a parentthreadID, each thread has a parentboardID - these are foreign keys to link up the various posts/threads etc.

In addition each board/thread has a name.

My question is, is there a query I can issue in mySQL involving joins or something else that will allow me to return the boardID, board_name, threadID, thread_name and perhaps other fields for a given postID?

Eg:

postID=30, parentthreadID for that post = 5, so look up thread no5, find out parentboardID, find name etc.....

It is the fact that three tables (at least) are involved that is confusing me

...

Posted: Fri Jul 25, 2003 12:09 pm
by kettle_drum
SELECT table1.field1, table1.field2, table2.field1, table2.field2 FROM table1, table2 WHERE table1.field1 = 'TRUE'

Posted: Fri Jul 25, 2003 6:48 pm
by RFairey
Hmmm......

What I really want is somthing like:

SELECT table1.field1, table1.field2, table2.field, table3.field FROM table1, table2, table3 WHERE table3.ield=a number AND return related info from table1 and 2

I only want one row in the result, the query has to work backwards up the tables to find all the data if you see what I mean.