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

  • SEARCH
  • Home
  • 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 6131081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:58+00:00 2026-05-23T16:55:58+00:00

EDIT: I have written it a bit wrong gill change my Q I’m a

  • 0

EDIT: I have written it a bit wrong gill change my Q

I’m a newbie with SQL and I have a Q..

I made 2 Temp. Tables.
Each has 25 Rows.(DateValue)

I want to combine this 2 tables in a third table..
First Table is [From]
Second Table is [To]…
Both tables have different values

I want to get it like this:

From| To |
1111|2222
2222|3333
3333|4444

etc..

I use this simple Query

Create Table #T3
( 
   [From] Datetime
   ,[To] Datetime
)

INSERT  Into #T3
SELECT Distinct #T1.[From], #T2.[To]
From #T1,#T2
Where #T1.[From] is not null
And #T2.[To] is not null

Select * from  #T3

Drop Table #T3
Drop Table #T2
Drop Table #T1

But my results are like this

From| To |
1111|1111
1111|2222
1111|3333
2222|1111
2222|2222
2222|3333

It multiplies the first field with the second wich gives me alot more records back..

Any help ?
THANKS !

  • 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-23T16:55:58+00:00Added an answer on May 23, 2026 at 4:55 pm

    After the OP’s edit

    This may work as you want (which is not entirely clear):

    INSERT INTO #T3 
      SELECT #T1.[From]
           , MIN(#T2.[To]) 
      FROM #T1
        JOIN #T2
          ON #T1.[From] < #T2.[To]
      GROUP BY #T1.[From]
    

    Using

    FROM T1, T2
    

    results in all combinations or rows of T1 and T2. It’s called a cross product and (properly) used with CROSS JOIN, like this:

    FROM T1 CROSS JOIN T2
    

    When you want to join the two tables based on a condition (and not get the cross product), you use a JOIN or INNER JOIN (these two are same thing):

    FROM T1 JOIN T2
      ON T1.[From] = T2.[To]
    

    will get you all rows combinations where T1.From matches T2.To (on equality). I suppose you wanted to match every row of T1 with the row of T2 where T2.To was just larger than T1.From so I used the “smaller than” < operator instead of the “equality” = operator.

    The GROUP BY and MIN() were added to get only the one with smallest T2.To from those rows.

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

Sidebar

Related Questions

I have a form with add, edit, and save buttons. The form also has
I have written quite a bit of code of the past few years. I've
I have written a really small 64-bit application that crashes on clean installations of
Edit: I have solved this by myself. See my answer below I have set
EDIT: I have submitted a bug report and Microsoft have acknowledge that it is
EDIT: I have added Slug column to address performance issues on specific record selection.
EDIT: I have fixed all but two warnings now, so thank you all for
EDIT: I have edited my post... Working on a project (c#), I have a
EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i
EDIT: I have realized the source of my problem. I only have count information

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.