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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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! |
| |||
| "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. |
| |||
| 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? |
| ||||
| 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. |