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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:06:03+00:00 2026-05-23T09:06:03+00:00

I have two tables with some ID’s and I need a query that returns

  • 0

I have two tables with some ID’s and I need a query that returns the following:

new_bet_id  old_bet_id  new_id  old_id
110         120         1       2
130         140         3       4
150         160         5       6

I’m having no problem getting new_bet_id correct, its the old_bet_id i,m having problem with since its from the same column. The new_id will me mapped with new_bet_id and old_id will be mapped with old_bet_id

So far I’ve tried the following:

SELECT 
one.bet_id as new_bet_id,
null as old_bet_id,
two.new_id,
two.old_id

FROM test_table_two two 
JOIN test_table_one one ON one.kund_id = two.new_id

UNION

SELECT
null  as new_bet_id,
one.bet_id as old_bet_id,
two.new_id,
two.old_id

FROM test_table_two two 
JOIN test_table_one one ON one.kund_id = two.old_id

But the result isn’t really what i’m looking for:

new_bet_id  old_bet_id  new_id  old_id
110         null        1       2
130         null        3       4
150         null        5       6
null        120         1       2
null        140         3       4
null        160         5       6

Below is the database setup for this example

CREATE TABLE test_table_one
(bet_id int,
kund_id int);

CREATE TABLE test_table_two
(new_id int,
old_id int);

insert into test_table_one values(110,1);
insert into test_table_one values(120,2);
insert into test_table_one values(130,3);
insert into test_table_one values(140,4);
insert into test_table_one values(150,5);
insert into test_table_one values(160,6);

insert into test_table_two values(1,2);
insert into test_table_two values(3,4);
insert into test_table_two values(5,6);

Hope someone can figure this out, 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-23T09:06:04+00:00Added an answer on May 23, 2026 at 9:06 am

    UNION gives you more rows. If you don’t want more rows, it’s the wrong tool.

    SELECT
      oneA.bet_id as new_bet_id,
      oneB.bet_id as old_bet_id,
      two.new_id,
      two.old_id
    FROM test_table_two two
      JOIN test_table_one oneA ON two.new_id = oneA.kund_id
      JOIN test_table_one oneB ON two.old_id = oneB.kund_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a MySQL query. I have two tables, one with
Need some help joining these two tables I have two views that looks like
High level I have two tables that need to have some of the data
I'm having some problems trying to perform a query. I have two tables, one
I need some help writing a SQL statement. I have two tables in a
I am looking for some help with a MYSQL query. I have two tables,
I have two tables that I am trying to join in a query, but
I have two tables, that is joined in some way. I've spent the last
I have two tables which have some transactional stuff stored in them. There will
I basically created some tables to play around with: I have Two main tables,

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.