|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
i have several Paragraphs in one table, how to do this: Can I regroup Paragraphs base on a number? For example, I have 3 Paragraphs: 1. Test1 2. Test2 3. Test3 if I pass 2, will regroup as: Test1, Test2 Test1, Test3 Test2, Test3 Test3, Test1 Test3, Test2 Can I do this in a query? Thanks. js
I'm not sure that understood you. What is the point of the query? CREATE TABLE Test (gr INT NOT NULL PRIMARY KEY,descr VARCHAR(10) NOT NULL) INSERT INTO Test VALUES (1,'Test1') INSERT INTO Test VALUES (2,'Test2') INSERT INTO Test VALUES (3,'Test3') GO SELECT DISTINCT Test.descr,T1.descr FROM Test JOIN Numbers N ON N.n<2 JOIN Test T1 ON T1.gr<=Test.gr ORDER BY t1.descr ASC Note: You will be better of doing such things on the client side Show quote "js" <js@some***@hotmail.com> wrote in message news:%23vwWeofWGHA.4212@TK2MSFTNGP02.phx.gbl... > Hi, > > i have several Paragraphs in one table, how to do this: > > Can I regroup Paragraphs base on a number? > > For example, > > I have 3 Paragraphs: > > 1. Test1 > > 2. Test2 > > 3. Test3 > > > > if I pass 2, will regroup as: > > Test1, Test2 > > Test1, Test3 > > Test2, Test3 > > Test3, Test1 > > Test3, Test2 > > > > Can I do this in a query? Thanks. > > > > If you pass 2?
You mean you are passing the number of times you want to join the table to itself? If you want to get every possible combination of X number of values within a set, dont do it in SQL. However, if this is an acedemic question, I think you want: Select a.paragraph, b.paragraph from sometable a full outer join sometable b on a.paragraph <> b.paragraph repeat the join for as many paragraphs as you want returned. However, I don't think it makes any sense to to this in SQL. If you want a random result, you can retrieve 3 random rows from the database with a trick that has been posted here a few time. Look for NEWID and TOP. Show quote "js" <js@some***@hotmail.com> wrote in message news:%23vwWeofWGHA.4212@TK2MSFTNGP02.phx.gbl... > Hi, > > i have several Paragraphs in one table, how to do this: > > Can I regroup Paragraphs base on a number? > > For example, > > I have 3 Paragraphs: > > 1. Test1 > > 2. Test2 > > 3. Test3 > > > > if I pass 2, will regroup as: > > Test1, Test2 > > Test1, Test3 > > Test2, Test3 > > Test3, Test1 > > Test3, Test2 > > > > Can I do this in a query? Thanks. > > > > |
|||||||||||||||||||||||