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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:42:55+00:00 2026-05-21T06:42:55+00:00

I created a simple test case: CREATE TABLE `t1` ( `id` int NOT NULL

  • 0

I created a simple test case:

CREATE TABLE `t1` (
  `id` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
)

CREATE TABLE `t2` (
  `id2` int NOT NULL AUTO_INCREMENT,
  `id1` int,
  PRIMARY KEY (`id2`)
)

CREATE TABLE `t3` (
  `id3` int NOT NULL AUTO_INCREMENT,
  `id1` int,
  PRIMARY KEY (`id3`)
)

insert into t1 (id) values (1);

insert into t2 (id1) values (1),(1);

insert into t3 (id1) values (1),(1),(1),(1);

I need to select all DISTINCT data from t1 left join t2 and DISTINCT data from t1 left join t3, returning a total of 6 rows ,1 x (2 [from t2] + 4 [from t3]) = 6, but beacause of the nature of this join I get 8 rows, 1 [from t1] x 2 [from t2] x 4 [from t3] = 8.

select * from t1 left join t2 on (t1.id = t2.id1);
2 rows in set (0.00 sec)

select * from t1 left join t3 on (t1.id = t3.id1);
4 rows in set (0.00 sec)

select * from t1 left join t2 on (t1.id = t2.id1) left join t3 on (t1.id = t3.id1);
8 rows in set (0.00 sec)

select * from t1 left join t2 on (t1.id = t2.id1) union select * from t1 left join t3 on (t1.id = t3.id1);
4 rows in set (0.00 sec)

What query should I use to get just the 6 rows I need, is it posible without subquery’s or I need them (It will be more complicatet in the big query where I need this) ?
I need this for a big query where I allready get data from 8 tables, but I need to get data from 2 more to get all the data I need in just one single query, but when joining the 9th table, the returned data get’s duplicated (the 9th table in this simple test case would be t3, and the 8th will be t2).

I hope someone could show me the right path to follow.
Thank you.

UPDATE SOLVED:
I realy don’t know how to do this test case in one select, but in my BIG query I solved it this way: beacause I used group_concat and group by, I did it by spliting a value in multipe group_concat(DISTINCT … ) and concat all of them like this

// instead of this
... group_concat(DISTINCT concat(val1, val2, val3)) ...
// I did this
concat(group_concat(DISTINCT val1,val2), group_concat(DISTINCT val1,val3)) ... 

so the distinct on small groups of value prevent all of those duplicates.

  • 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-21T06:42:56+00:00Added an answer on May 21, 2026 at 6:42 am

    I’m not sure if you’re looking for at this solution

    select * from t1 left join t2 on (t1.id = t2.id1);
    union all
    select * from t1 left join t3 on (t1.id = t3.id1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple case: i put a DataTable in Cache DataTable table = SomeClass.GetTable(); Cache[test] =
I created a simple test case that replicates an issue I'm having. I'm walking
I've created a simple test case exhibiting a strange behavior I've noticed in a
I created a simple test page on my website www.xaisoft.com and it had no
I created a simple test with SendKeys, and tried both SendWait and Send. Private
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and
I am using SQL Server 2008 Enterprise. I have created a very simple test
I installed JDeveloper 11.1.1.6 and opened a simple test project that was originally created
I created a simple application inspired by this example in order to test all
I created two very simple Heroku apps to test out the service, but it's

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.