Home » SQL & PL/SQL » SQL & PL/SQL » Exclude records from the beginning and the end of a table
Exclude records from the beginning and the end of a table [message #209727] Sun, 17 December 2006 07:40 Go to next message
geok_100
Messages: 3
Registered: December 2006
Junior Member
Hello,

I have a table with multiple fields, which describe several products.I want to exclude all the records of a specific product when it appears at the beginning or at the end of the table. Let's say, that the table is similar to the following, I want to exclude all products A from the beginning and the end. I have been told that I should use cursors but i am not very sure how to do it.
thank you all in advance for your answers.
e.g.
A
A
A
B
D
G
S
A
A
Re: Exclude records from the beginning and the end of a table [message #209735 is a reply to message #209727] Sun, 17 December 2006 08:01 Go to previous messageGo to next message
Littlefoot
Messages: 20892
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
The main problem here isn't excluding records, but finding them. As RDBMS's don't know "beginning" or "end" of a table, you'll have to find a way to distinguish which records belong to the "beginning" and which to the "end". ORDER BY clause is to be used to do that.

So, do you have any column in your table which will be used to uniquely know which A's should be excluded?

Also, you might want to use Google to search for more information about the issue (regarding order of records in a relational table).
Re: Exclude records from the beginning and the end of a table [message #209751 is a reply to message #209735] Sun, 17 December 2006 09:19 Go to previous messageGo to next message
geok_100
Messages: 3
Registered: December 2006
Junior Member
There is a column "Date" according to which the table is ordered. The point is that i want to exclude from my table the first and last rows only when thet refer to a specific product. As I said there are multiple products, but there is one which i want it out if it appears at the beginning or at the end of that sorted table.
Re: Exclude records from the beginning and the end of a table [message #209757 is a reply to message #209751] Sun, 17 December 2006 10:59 Go to previous message
Littlefoot
Messages: 20892
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I still don't quite understand - do you want to get rid of ALL A's from the first post (because there are A products at the beginning and at the end), or only first and last A? Or something different?

It would be easier to understand if you post some sample data (those include CREATE TABLE and INSERT INTO statements), preferred output and - why not - query YOU used to solve the problem. Doesn't matter it doesn't work (yet), but it would show that you made some effort in solving the problem.
Previous Topic: outer join help
Next Topic: back ground tables
Goto Forum:
  


Current Time: Mon Dec 05 02:38:36 CST 2016

Total time taken to generate the page: 0.05551 seconds