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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 selecting distinct repeatitive pattern from a table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-06-17 : 08:42:51
jarad writes "I have a table that represent assembly lines. Each assembly lines has 3 tools on it. Each time a part goes through each tool in assembly line an entery is made into the assembly lines table.
To finish a part it goes through 3 tools therefore 3 entries in assembly lines table. This gets repeated many time per assembly lines as parts are made. There is no order how the data entered into the assembly lines table. Each assembly line is give a unique line number.I need to write a query that retrieve the latest entery from each group of line numbers. The table look something like this:
ID, LineNumber, LineType and etc
Here are lineNumbers that keep repeating there are many of them but I am putting only couple of them as sample.
330G
330G
330G
330E
330E
330E
330E
330E
330E
330G
330E
330G
330G
330E
330E

In this case I want to retrieve the last 3 of each catagory one after another. In other words, want to get back 3 330G in a row then the other 3 330E. I need to grab the latest entries.
I am using sqlserver 2000 with service pack 4 on windows 2000
Thanks in advance for any help"

KLang23
Posting Yak Master

115 Posts

Posted - 2005-06-17 : 14:18:37
Wow!!

The physical order of rows in a table is absolutely meaningless for retrieval operations. It has value internally for performance as relating to clustering, but you can NEVER assume that the order that the rows go in is the order that they will come out.

In your example where rows are grouped by the entry-order, there is no way to process them the way you want unless you add additional identifiers (such as a datetime stamp).

Sorry. :(
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-06-17 : 14:32:43
Read the link below and maybe we can help....



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -