MySQL Forums
Forum List  »  Newbie

Re: Joining results from two tables
Posted by: Phillip Ward
Date: January 12, 2018 09:36AM

Quote

Your suggestion means I have to bin that and have 5 rows per id in one table and 2 per id in the second table ...

Yep! That's right.

Quote

... which makes the id not unique and will be duplicated on several rows.

So what? Do you ever need to access ID #16659352956492, which happens to be ball #3 from the draw made on the 02/04/06? (Whenever that is?)
I would be surprised if you did.

These groups of rows exist as "units"; you wouldn't have three of them without the rest, but they're structured in a way that better suits your database server, which is important if you worry about Performance. With hundreds of rows, it'll manage - with millions, I suspect it would struggle.

You're most of the way there to joining one query to another.
Those brackets that you have wrapped around all those union'ed selects are one part of it; adding a "table alias" to that bracketed sub-expression is the second.

select t0.*, t1.* 
from 
( select * 
  from ... 
) t0 
inner join 
( select * 
  from ... 
) t1 
on t0.? = t1.?

Replace each select above with your existing queries and change the "on" clauses to join them appropriately.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Joining results from two tables
January 12, 2018 09:36AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.