According to the documentation, mySQL does not support subselects in queries... so i'm not exactly sure if this is possible to do in one query statement.

I'm setting up a forum, where I have 3 basic tables.

forum_msgs, forum_threads, forum_forums.

forum_msgs has an msgID and a threadID (along with other msg information)

forum_threads has a threadID and a forumID (along with other thread information)

forum_forums has a forumID and a projID (each forum is attached to a particular project in another table)

What I would like to do is given a msgID, find out what the projID is.

Using subselects, it would be something like:
SELECT f.projID FROM forum_forums f WHERE f.forumID = (SELECT t.forumID FROM forum_threads t WHERE t.threadID = (SELECT m.threadID FROM forum_msgs m WHERE m.msgID = $someMsgID))

How can I do this query in mySQL which doesn't support subselects? and possibly without doing like 3 separate queries.

    What you can probably do is use something like

    select f.projID from forum_forums f, forum_threads t, forum_msgs m where f.forumID=t.forumID and t.threadID=m.threadID and m.msgID=$someMsgID

    not tested though, but I think this will do the trick.

      • [deleted]

      Sounds to me like you need to learn what JOIN means :-)
      You are using sub-selected where a JOIN is much more appropriate.
      Read Edwards reply and see how he used it.

        its actually pretty much exactly what I had... but it wasn't working for me... so i figured i wasn't thinking about it correctly. Thanks for the help.

          Write a Reply...