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 4616526
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:59:38+00:00 2026-05-22T01:59:38+00:00

I have two tables structured like this: table a id title date 1 testing1

  • 0

I have two tables structured like this:

table a

id title   date
1  testing1 2001-05
1  testing2 2003-05

table b

id code   date
1  aaaa 2001-01
1  bbbb 2003-01

When I join these two tables, I am getting three rows, but I only want 2?

(query)
select distinct a.*, b.*
from table a, table b
where a.date in ('2001-05','2003-05')
and a.id=b.id
and b.date < a.date  ---> I know the error is coming from here.

wrong output looks like this

id title   date     id   code   date
1  testing1 2001-05 1    aaaa   2001-01
1  testing1 2003-05 1    aaaa   2003-01-------this is duplicated because the date is in fact less than, 
1  testing2 2003-05 1    bbbb   2003-01

correct output should be:

id title   date     id   code   date
1  testing1 2001-05 1    aaaa   2001-01
1  testing2 2003-05 1    bbbb   2003-01
  • 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-22T01:59:38+00:00Added an answer on May 22, 2026 at 1:59 am
    Select A.id, A.title, A.date
        , B.id, B.code, B.date
    From TableA As A
        Join    (
                Select A.id, A.title, A.date
                    , Min( B.Date ) As BDate
                From TableA As A
                    Left Join TableB As B
                        On B.id = A.id
                            And B.Date < A.Date
                Where A.Date In('2001-05-01','2003-05-01')
                Group By A.id, A.title, A.date
                ) As Z
            On Z.id = A.id
                And Z.title = A.title
                And Z.date = A.date
        Join TableB As B
            On B.id = A.id
                And B.date = Z.BDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, structured like so: table A: A_ID varchar(32) PRIMARY KEY field1
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two SQL tables with data that I would like to compare. The
I'd like to get suggestion in both C# and VB.NET I have two tables
I hope I can explain this clearly: I have two tables with the following
I have two tables that I'm querying from. In one table, there are fields
I have two table structures like these: episodes ( episode_id MEDIUMINT(8) UNSIGNED NOT NULL
I have a situation like, I have two tables having same structure. I have
I have two tables with hierarchyid fields, one of which is a staging table

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.