Jump to content

Mysql Joining Queries


Andy11548

Recommended Posts

Hello,

 

I could do with some help joining this query in to another query. I'm completely and utterly blagged on what I'm doing now.

 

I need this query:

mysql_query("SELECT * FROM `users` WHERE `username`='".$_SESSION[username]."'");

 

placed into this one:

mysql_query("
	   SELECT
	   f1.cat_name as CatName,
	   f1.cat_id as CatID,
	   f2.cat_id as SubCatID,
	   f2.sub_id as SubID,
	   f2.sub_name as SubName,
	   f2.sub_desc as SubDesc,
	   f3.topic_id as TopicID,
	   f3.user_id as UserTopicID,
	   f3.topic_name as TopicName,
	   f3.topic_message as TopicMessage,
	   f4.user_id as UserReplyID,
	   f5.username as Username,
	   
	   (SELECT COUNT(*) FROM forum_topics as f3 WHERE f3.sub_id = f2.sub_id) as TopicAMT,
	   (SELECT COUNT(*) FROM forum_replies as f4 WHERE f4.topic_id = f3.topic_id) as ReplyAMT
	   
	   FROM `forum_cats` as f1
	   		LEFT JOIN `forum_sub` as f2
	   			ON f1.cat_id = f2.cat_id
	   		LEFT JOIN `forum_topics` as f3
	   			ON f2.sub_id = f3.sub_id
	   		LEFT JOIN `forum_replies` as f4
	   			ON f3.topic_id = f4.topic_id
	   		LEFT JOIN `users` as f5
	   			ON f4.user_id = f5.user_id
	   			
	 WHERE f1.cat_id='$cat' $getSub $getTopic

	 ORDER BY f2.sub_id ASC, f4.reply_id DESC
	 ");

 

Help would be appreciated.

 

Thanks,

Andy.

Link to comment
https://forums.phpfreaks.com/topic/267224-mysql-joining-queries/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.