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
Help with mySQL query
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
SELECT table1.field1, table1.field2, table2.field1, table2.field2 FROM table1, table2 WHERE table1.field1 = 'TRUE'
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.
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.