Jump to content

massive query


Julius

Recommended Posts

Hi,

 

I have 5 tables:

 

categories

      id, name

forums

    id, cat_id, name, description

topics

    id, forum_id, name, date, user_id

posts

    id, topic_id, post, date, user_id

users

    id, nick, password

 

im trying to make a forum. on the main page of it, i want to show category name(will be at least 3 categories), forum name and description, latest post in that forum author name and topic name where post was posted. I want to make as less queries as i can. so, can anyone help me with that? I need: name from categories table, name from forums table, name from topics table, latest post user_id from posts table, nick from users table where id=user_id (from posts). can this all be retrieved with one query?

Link to comment
Share on other sites

what do you mean? i have heard about 'join', googled for it, found some examples, tried, but they don't do exactly what I want. I dont want you to write the whole query for me, just give me a hint. what i tried:

SELECT categories.name, forums.name, topics.name,
posts.date, users.nick
FROM categories LEFT JOIN (forums, topics, posts, users)
ON (forums.cat_id=categories.id AND topics.fid=forums.id AND posts.tid=topics.id AND users.id=posts.author)

i think this might do the trick after some modifications, am I thinking right? this query takes only one forum (but there are three of them).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.