V Posted July 18, 2010 Share Posted July 18, 2010 I've been struggling to combine 2 queries but I keep getting errors. They are.. "SELECT topics.*, categories.* FROM topics, categories WHERE topics.cat_id = categories.cat_id AND topics.views >= 2 ORDER BY topic_date DESC"; and "SELECT *, COUNT(post_id) as total_posts FROM posts WHERE topic_id = {$row["topic_id"]} ORDER BY post_date DESC"; Is it even possible to combine them? Pls help. Quote Link to comment https://forums.phpfreaks.com/topic/208105-cant-combine-2-queries/ Share on other sites More sharing options...
grissom Posted July 19, 2010 Share Posted July 19, 2010 try : ... ORDER BY topics.topic_date DESC lemme know if that works Quote Link to comment https://forums.phpfreaks.com/topic/208105-cant-combine-2-queries/#findComment-1088079 Share on other sites More sharing options...
Mchl Posted July 19, 2010 Share Posted July 19, 2010 What's the relation between posts table and two other tables? Quote Link to comment https://forums.phpfreaks.com/topic/208105-cant-combine-2-queries/#findComment-1088093 Share on other sites More sharing options...
V Posted July 19, 2010 Author Share Posted July 19, 2010 grissom, hmm I'm not sure where to add that, I'm trying to figure out how to combine the 2. Mchl, In the first query, the Topics table are like subcategories of the Category table. Each Category as a number of Topics. topics.views >= 2 is the unique views of a topic (for a "sort by") script I wrote. So I'll also have for example topics.comments >=5 for most commented. Combing the 2 queries would be ideal because I can query just once for each condition. And the second query tells the total number of posts that are in a topic. So both should echo out Topic Name ....... Category (it belongs to) ........... Total Number of Posts Hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/208105-cant-combine-2-queries/#findComment-1088204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.