Unix Technical Forum

Complicated UNION query

This is a discussion on Complicated UNION query within the MySQL forums, part of the Database Server Software category; --> Hello all I need to make a UNION query from at least 2 identical tables, and I have to ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:26 AM
JalaL
 
Posts: n/a
Default Complicated UNION query

Hello all

I need to make a UNION query from at least 2 identical tables, and I have to
make a JOIN query within each part of the query

I want to do something like (doesn't work)

(SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2) WHERE
some conditions)
UNION
(SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2) WHERE
some conditions)
GROUP BY one field from table 1
ORDER BY some fields from table1 and table2
LIMIT 0, 10

In SELECT I use some MIN(), MAX() ans SUM that's why I used GROUP BY

Can somebody help me please



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: Complicated UNION query

On 21 Mar, 01:49, "JalaL" <nos...@nospam.com> wrote:
> Hello all
>
> I need to make a UNION query from at least 2 identical tables, and I have to
> make a JOIN query within each part of the query
>
> I want to do something like (doesn't work)
>
> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2) WHERE
> some conditions)
> UNION
> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2) WHERE
> some conditions)
> GROUP BY one field from table 1
> ORDER BY some fields from table1 and table2
> LIMIT 0, 10
>
> In SELECT I use some MIN(), MAX() ans SUM that's why I used GROUP BY
>
> Can somebody help me please


"doesn't work"!!!

Very helpful!

What about it DOESN'T WORK!!!!!

Is there a syntax error?
Does it produce out put but not what you want?

Help us to help you!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:27 AM
JalaL
 
Posts: n/a
Default Re: Complicated UNION query


"Captain Paralytic" <paul_lautman@yahoo.com> a écrit dans le message de
news: 1174469847.705000.117660@n59g2000hsh.googlegroups. com...
> On 21 Mar, 01:49, "JalaL" <nos...@nospam.com> wrote:
>> Hello all
>>
>> I need to make a UNION query from at least 2 identical tables, and I have
>> to
>> make a JOIN query within each part of the query
>>
>> I want to do something like (doesn't work)
>>
>> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
>> WHERE
>> some conditions)
>> UNION
>> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
>> WHERE
>> some conditions)
>> GROUP BY one field from table 1
>> ORDER BY some fields from table1 and table2
>> LIMIT 0, 10
>>
>> In SELECT I use some MIN(), MAX() ans SUM that's why I used GROUP BY
>>
>> Can somebody help me please

>
> "doesn't work"!!!
>
> Very helpful!
>
> What about it DOESN'T WORK!!!!!
>
> Is there a syntax error?
> Does it produce out put but not what you want?
>
> Help us to help you!
>


Oups, sorry... The query works only if I remove GROUP BY and ORDER BY and it
takes very long time to execute, I have a very large table that's why I
wanted to split it into small identical tables. I think mysql doesn't
support joining tables in union.

I think creating a temporary MERGE table each time works faster.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: Complicated UNION query

On 21 Mar, 14:48, "JalaL" <nos...@nospam.com> wrote:
> "Captain Paralytic" <paul_laut...@yahoo.com> a écrit dans le message denews: 1174469847.705000.117__BEGIN_MASK_n#9g02mG7!__..._ _END_MASK_i?a63jfAD$z__@n59g2000hsh.googlegroups.c om...
>
>
>
>
>
> > On 21 Mar, 01:49, "JalaL" <nos...@nospam.com> wrote:
> >> Hello all

>
> >> I need to make a UNION query from at least 2 identical tables, and I have
> >> to
> >> make a JOIN query within each part of the query

>
> >> I want to do something like (doesn't work)

>
> >> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
> >> WHERE
> >> some conditions)
> >> UNION
> >> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
> >> WHERE
> >> some conditions)
> >> GROUP BY one field from table 1
> >> ORDER BY some fields from table1 and table2
> >> LIMIT 0, 10

>
> >> In SELECT I use some MIN(), MAX() ans SUM that's why I used GROUP BY

>
> >> Can somebody help me please

>
> > "doesn't work"!!!

>
> > Very helpful!

>
> > What about it DOESN'T WORK!!!!!

>
> > Is there a syntax error?
> > Does it produce out put but not what you want?

>
> > Help us to help you!

>
> Oups, sorry... The query works only if I remove GROUP BY and ORDER BY andit
> takes very long time to execute, I have a very large table that's why I
> wanted to split it into small identical tables. I think mysql doesn't
> support joining tables in union.
>
> I think creating a temporary MERGE table each time works faster.- Hide quoted text -
>
> - Show quoted text -


Sheesh, so now you tell us when it works, but you STILL haven't told
us in what way it fails when it doesn't work!

You say that "I think mysql doesn't support joining tables in union."
but there is no JOIN in your query.

You have made some statements like: "I need to make a UNION query from
at least 2 identical tables", but haven't explained why you need to do
this.

You haven't even shown us a real query!

If you want us to help you, you really must be more specific!

Care to try again?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:28 AM
Christopher Pomasl
 
Posts: n/a
Default Re: Complicated UNION query

The GROUP BY is based on the subselect not the full select so each SELECT
statement in the UNION needs its own GROUP BY.

CJP

On Wed, 21 Mar 2007 15:48:42 +0100, JalaL wrote:

>
> "Captain Paralytic" <paul_lautman@yahoo.com> a écrit dans le message de
> news: 1174469847.705000.117660@n59g2000hsh.googlegroups. com...
>> On 21 Mar, 01:49, "JalaL" <nos...@nospam.com> wrote:
>>> Hello all
>>>
>>> I need to make a UNION query from at least 2 identical tables, and I have
>>> to
>>> make a JOIN query within each part of the query
>>>
>>> I want to do something like (doesn't work)
>>>
>>> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
>>> WHERE
>>> some conditions)
>>> UNION
>>> (SELECT some fields from table1 and table2 FROM (table1 t1, table2 t2)
>>> WHERE
>>> some conditions)
>>> GROUP BY one field from table 1
>>> ORDER BY some fields from table1 and table2
>>> LIMIT 0, 10
>>>
>>> In SELECT I use some MIN(), MAX() ans SUM that's why I used GROUP BY
>>>
>>> Can somebody help me please

>>
>> "doesn't work"!!!
>>
>> Very helpful!
>>
>> What about it DOESN'T WORK!!!!!
>>
>> Is there a syntax error?
>> Does it produce out put but not what you want?
>>
>> Help us to help you!
>>

>
> Oups, sorry... The query works only if I remove GROUP BY and ORDER BY and it
> takes very long time to execute, I have a very large table that's why I
> wanted to split it into small identical tables. I think mysql doesn't
> support joining tables in union.
>
> I think creating a temporary MERGE table each time works faster.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com