Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:40:15+00:00 2026-05-26T17:40:15+00:00

I have two tables. One that keeps all of my threads started on a

  • 0

I have two tables. One that keeps all of my threads started on a subject and another that keeps all the posts that related to each thread. They are both using the “id” columns for relation purposes. For example the very first thread (AKA subject) opened up has three comments total on it including the original post. For this example I have taken the irrelevant columns and named them consecutive column names such as col1-col6. I do still need all of these columns returned in the query results though!

table – dbo.Threads (parent table)


id  col1  timestamp                col2  col3  col4  col5  subject
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue
2   7     2011-11-07 14:53:01.410  6     NULL  2     0     Request 2 blah green
3   6     2011-11-07 14:54:01.453  6     NULL  3     0     Request 3 blah red
4   7     2011-11-08 10:50:57.440  6     NULL  3     0     Request 4 blah black

table – dbo.Posts (child table)


id  timestamp                  col6  post
1   2011-11-07 14:52:08.710    3     This is the 1st orange post for one
2   2011-11-07 14:53:01.420    3     This is the 1st green post for two
3   2011-11-07 14:54:01.463    3     This is the 1st blue post for three
1   2011-11-08 15:08:59.707    3     This is the 2nd red post for one
1   2011-11-09 15:09:16.333    3     This is the 3rd black post for one
4   2011-11-08 10:50:57.527    3     This is the 1st yellow post for four

Currently I have tried using the following query just for testing…


"SELECT Threads.*, Posts.* FROM Threads INNER JOIN Posts ON Threads.id = Posts.id ORDER BY Posts.timestamp"

This returns the following…


id  col1  timestamp                col2  col3  col4  col5  subject               id  timestamp                col6  post
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue   1   2011-11-07 14:52:08.710  3     This is the 1st orange post for one
2   7     2011-11-07 14:53:01.410  6     NULL  2     0     Request 2 blah green  2   2011-11-07 14:53:01.420  3     This is the 1st green post for two
3   6     2011-11-07 14:54:01.453  6     NULL  3     0     Request 3 blah red    3   2011-11-07 14:54:01.463  3     This is the 1st blue post for three
4   7     2011-11-08 10:50:57.440  6     NULL  3     0     Request 4 blah black  4   2011-11-08 10:50:57.527  3     This is the 1st yellow post for four
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue   1   2011-11-08 15:08:59.707  3     This is the 2nd red post for one
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue   1   2011-11-09 15:09:16.333  3     This is the 3rd black post for one

I need to have a query that will search both the dbo.Threads.subject column and the dbo.Posts.post column for a text crietera. In this example I will use “blue”. Currently I have tried using the following query…


"SELECT Threads.*, Posts.* FROM Threads INNER JOIN Posts ON Threads.id = Posts.id WHERE ((Threads.subject LIKE '%blue%') OR (Posts.post LIKE '%blue%')) ORDER BY Posts.timestamp"

This returns the following…


id  col1  timestamp                col2  col3  col4  col5  subject              id  timestamp                col6  post
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue  1   2011-11-07 14:52:08.710  3     This is the 1st orange post for one
3   6     2011-11-07 14:54:01.453  6     NULL  3     0     Request 3 blah red   3   2011-11-07 14:54:01.463  3     This is the 1st blue post for three
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue  1   2011-11-08 15:08:59.707  3     This is the 2nd red post for one
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue  1   2011-11-09 15:09:16.333  3     This is the 3rd black post for one

That is ALMOST exactly what I needed as the results… I currently need it to return the same exact results but without the last two lines. I only want unique id’s returned. In this case I do not want three results for id “1” to be returned, I only want one result for “1” to be returned and then of course one results returned for “3” giving me the following results…


id  col1  timestamp                col2  col3  col4  col5  subject              id  timestamp                col6  post
1   6     2011-11-07 14:52:08.650  6     NULL  3     0     Request 1 blah blue  1   2011-11-07 14:52:08.710  3     This is the 1st orange post for one
3   6     2011-11-07 14:54:01.453  6     NULL  3     0     Request 3 blah red   3   2011-11-07 14:54:01.463  3     This is the 1st blue post for three

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:40:16+00:00Added an answer on May 26, 2026 at 5:40 pm
    SELECT T.*, P.* 
    FROM Threads 
    INNER JOIN POSTS P ON T.id = P.id 
    WHERE ((T.subject LIKE '%blue%') OR (P.post LIKE '%blue%')) 
    AND P.Timestamp = (Select min(P2.timestamp) from posts P2 where ID = T.ID) 
    ORDER BY P.timestamp
    

    –The and statement here is intended to get the earliest timestamp for the Thread.ID

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one that contains volunteers, and one that contains venues. Volunteers
Suppose I have two tables that are linked (one has a foreign key to
I have two tables, one is a table of forum threads. It has a
I have two tables related: DataEntered and Model DataEntered -currentModel Model One DataEntered can
I have two tables one has a three column composite key. The other needs
I have two tables, one stores the products and quantity we have bought, the
I have two tables, one for routes and one for airports. Routes contains just
I have two tables, one called cart and one called items. Now I want
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.