Sagewire Logo

Grouping Elements

4 Message(s) by 3 Author(s) originally posted in mysql discussion


From: Legend Date:   Saturday, October 20, 2007
I was wondering if it is possible to group linked elements using SQL
directly. For example, if I have some table like:

Column A | Column B | Column C | Column D
1 | 2 | A11 | A32
2 | 3 | A13 | A22
3 | 4 | A14 | A23
5 | 6 | A19 | A24
7 | 8 | A18 | A25
1 | 9 | A17 | A26

I want to group all linked items together. So in the above case my
output'd look something like:
Table 1:
1
2
3
4
9

Table 2:
5
6

Table 3:
7
8

or maybe something like with the above one still preferred:
1,2,3,4,9
5,6
7,8
extracted into another table...

One other question I had was, can a data base have a million tables? I
mean, if I had many such groups,'d it be efficient to create a
table for each group or is there any other approach?


From: Kees Nuyt Date:   Saturday, October 20, 2007
On Sat, 20 Oct 2007 05:38:22 -0000, Legend
wrote in message:

I was wondering if it is possible to group
linked elements using SQL directly.



A lot is possible with SQL.
It's not clear what you mean with 'linked'.

For example, if I have some table like:
Column A | Column B | Column C | Column D
1 | 2 | A11 | A32
2 | 3 | A13 | A22
3 | 4 | A14 | A23
5 | 6 | A19 | A24
7 | 8 | A18 | A25
1 | 9 | A17 | A26
I want to group all linked items together. So in the above case my
output'd look something like:
Table 1:
1
2
3
4
9
Table 2:
5
6
Table 3:
7
8My IQ is limited, I can not discover a reason why the given


input'd lead to the requested output.
Are you sure your sample data is exact?
Can you elaborate on what you are trying to achieve?

or maybe something like with the above one still preferred:
1,2,3,4,9
5,6
7,8
extracted into another table...



It can be done, but why store in another table?

One other question I had was, can a database have a million tables?



In general, even if physically possible, that's a very bad
idea, and a sure sign of a flaw in the database design.

I mean, if I had many such groups,'d it be efficient
to create a table for each group



No, not at all.

or is there any other approach?



Only store primary data in the database,
write views to look at the data in any way you want.
--
( Kees
)
c[_] Famous last words - Do not worry, I can handle it. (#441)


From: strawberry Date:   Saturday, October 20, 2007
wrote in message:
On Sat, 20 Oct 2007 05:38:22 -0000, Legend
wrote in message:
>I was wondering if it is possible to group
>linked elements using SQL directly.
A lot is possible with SQL.
It's not clear what you mean with 'linked'.
>For example, if I have some table like:
>Column A | Column B | Column C | Column D
>1 | 2 | A11 | A32
>2 | 3 | A13 | A22
>3 | 4 | A14 | A23
>5 | 6 | A19 | A24
>7 | 8 | A18 | A25
>1 | 9 | A17 | A26
>I want to group all linked items together. So in the above case my
>output'd look something like:
>Table 1:
>1
>2
>3
>4
>9
>Table 2:
>5
>6
>Table 3:
>7
>8
My IQ is limited, I can not discover a reason why the given
input'd lead to the requested output.
Are you sure your sample data is exact?
Can you elaborate on what you are trying to achieve?
>or maybe something like with the above one still preferred:
>1,2,3,4,9
>5,6
>7,8
>extracted into another table...
It can be done, but why store in another table?
>One other question I had was, can a database have a million tables?
In general, even if physically possible, that's a very bad
idea, and a sure sign of a flaw in the database design.
>I mean, if I had many such groups,'d it be efficient
>to create a table for each group
No, not at all.
>or is there any other approach?
Only store primary data in the database,
write views to look at the data in any way you want.
--
( Kees
)
c[_] Famous last words - Do not worry, I can handle it. (#441)



This question was also posted in mysql.com's own forums.

I understand the relationship between the dataset and the result set:
1 is linked to 4 via 2 & 3.
5 & 6 are linked directly, as are 7 & 8, and 1 & 9

So the OP wants a result that looks like:
1,2,3,4,9
5,6
7,8

This requires recursion, which can be achieved in a variety of ways,
including:

1. LEFT JOIN the table to itself as often as you think necessary to
traverse the tree.
2. Use a Stored Procedure
3. Use a nested set model instead of an adjacency list
4(my personal favourite). Use an external language (like php) to
handle the recursion
5. A combination of some of the above.


From: Kees Nuyt Date:   Saturday, October 20, 2007
On Sat, 20 Oct 2007 14:51:23 -0000, strawberry
wrote in message:

This question was also posted in mysql.com's own forums.
I understand the relationship between the dataset and the result set:
1 is linked to 4 via 2 & 3.
5 & 6 are linked directly, as are 7 & 8, and 1 & 9



Aha, now I see. Thanks for the clarification.
--
( Kees
)
c[_] I do not want to be your other half.
I believe that One and One make TWO.
(Alanis Morrisette: "Not the Doctor") (#185)



Next Message: Previous Row Comparison


Blogs related to Grouping Elements

xml generation tools
... xml multiple namespaces xml multiple root elements xml multiple schemas xml music feed xml music file xml music files xml music player xml mysql xml mysql database xml mysql import xml mysql java xml mysql php xml mysql tutorial xml ...

msdba.dll
... msde manager freeware msde manager serial msde manager v1.1.1 msde manual msde maryland msde memory msde memory allocation msde memory leak msde memory limit msde memory usage msde mysql msde named instance msde network cable 1722 ...

Több mint 600 AJAX szkriptet
Ajax Slider Bar Form Element. Update a value inside a MySQL Database using the AJAX method when drag stops. .... FX.Sort - Sort with style. This effect will rearrange a group of elements using a transition. ...

database driven menu asp
... sql database frontpage template database frontpage templates database fsbo home database fsbo home top database ftd movie database fuel management pump station system database fuengirola hosting mysql database full gale group text ...

list swore
... users group list users groups list users in a group list users in active directory list users in group list users in group active directory list users in group linux list users in group unix list users in linux list users in mysql ...

free web hosting hotlinking
... web hosting mysql free web hosting mysql image site free web hosting mysql php free web hosting mysql support free web hosting no ad banner free web hosting no ad banners free web hosting no adds free web hosting no adds php mysql ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional