Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sequence one table based on another table

Author  Topic 

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 09:37:21
Hello Friends,
I want to sequence the records of one table based on another table. For example: Table A has 7 seven records(it can vary)as follows:
TableA_ColumnA
1
2
55
4
5
66
7

Now there is another table B basically i contains less or same number of records as Table A.
TableB_ColumnA
66
1
2
7
5
Now i want the Table B record sequence to be arrange as of table A as follows:
TableB_ColumnA
1
2
5
66
7

Thanks.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 09:53:23
This is not a sequence that you can get using ORDER BY.
So is there another column to get this order?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 09:55:44
quote:
Originally posted by webfred

This is not a sequence that you can get using ORDER BY.
So is there another column to get this order?


No, you're never too old to Yak'n'Roll if you're too young to die.



No there is no other column. Can we do it using conditions and loops as i am using stored procedure?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 10:02:47
You can get the values without ORDER BY from a table but the outcoming sequence (i.e. order) is not reliable!

select tb.columnA
from tableA as ta
right join tableB tb
on ta.ColumnA = tb.ColumnA
where tb.ColumnA is not null


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-09 : 10:06:42
Please note that there's no concept of first and last in sql table so sequence doesnt make sense unless you define in terms of a column .
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 10:07:25
Is there any alternative, i want the sequence(i.e. order) to be reliable???

Thanks webfred.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 10:08:47
I see no chance without having a column to define the order by.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 10:20:01

Hello Visakh16,
I have an asp.net application that mostly behaves like a book(or manual). database table has hundred of records that contains the text of the manual. So when the end user clicks "next" on a web page, data should be retrieved accordingly. Every thing is working fine. Now the problem some users don't have access to certain chapters. So when the user clicks the "next" on a web page, data should be retrieved based on permissions he/she has.

Thanks.
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 10:22:13
Thanks webfred
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 10:22:40
then pagenumbers sequence 1,2,5,66,7 makes no sense.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-09 : 10:28:36
quote:
Originally posted by amodi


Hello Visakh16,
I have an asp.net application that mostly behaves like a book(or manual). database table has hundred of records that contains the text of the manual. So when the end user clicks "next" on a web page, data should be retrieved accordingly. Every thing is working fine. Now the problem some users don't have access to certain chapters. So when the user clicks the "next" on a web page, data should be retrieved based on permissions he/she has.

Thanks.


are you using sql 2005?
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-01-09 : 10:32:12
yes sql 2005 and stored procedures.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-09 : 10:35:25
ok. can you give sample data from table storing permission details and also table containing page details of book
Go to Top of Page
   

- Advertisement -