Jump to content
  • Advertisement
Sign in to follow this  
ArchG

[web] Making 2 SQL Queries into 1

This topic is 3831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I was recently doing some coding for some integration with my frontpage of my website, and the forum system (YAF)...and I ran into a common issue where I need pieces of info from different tables.
Info Needed

Table: yaf_topic
Fields Needed: Topic(varchar),TopicID(int)

Table: yaf_message
Fields Needed: Message(varchar), Posted(dateTime)
What I always do in these situation is pretty much just use 2 queries
Query1
"SELECT Topic, TopicID FROM yaf_topic WHERE ForumID = 4"

then Query2
"SELECT Message, Posted FROM yaf_message WHERE TopicID = (topicID from above)"
I just figured it's time to move to the next level and combine the 2...I just don't know how... Sorry for the newb question, anyone who takes the time to answer has my thanks. -ArchG

Share this post


Link to post
Share on other sites
Advertisement
SELECT Topic, TopicID, Message, Posted FROM yaf_topic INNER JOIN yaf_message.TopicID ON yaf_topic.TopicID = yaf_message WHERE ForumID = 4

or

SELECT Topic, TopicID, Message, Posted FROM yaf_topic NATURAL JOIN yaf_message WHERE ForumID = 4

Share this post


Link to post
Share on other sites
This should do it...

SELECT yt.TopicID, yt.Topic, ym.Message, ym.Posted
FROM yaf_topic yt
INNER JOIN yaf_message ym ON ym.TopicID = yt.TopicID
WHERE ForumID = @ForumID

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!