Help with mySQL query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
RFairey
Forum Commoner
Posts: 52
Joined: Fri Jun 06, 2003 5:23 pm

Help with mySQL query

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

SELECT table1.field1, table1.field2, table2.field1, table2.field2 FROM table1, table2 WHERE table1.field1 = 'TRUE'
RFairey
Forum Commoner
Posts: 52
Joined: Fri Jun 06, 2003 5:23 pm

Post 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.
Post Reply