how we delete 3rd row from one table

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
rahul.boju
Participant
Posts: 1
Joined: Wed Aug 10, 2011 11:42 am

how we delete 3rd row from one table

Post by rahul.boju »

please let me know the answer thanks in advance :?
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

interview question??
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's a trick question! :shock:
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

In which database?

Please let us know, how you will select only the 3rd row from your table?
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Technically, your first question is irrelevant. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

chulett wrote:Technically, your first question is irrelevant. :wink:


My guess is, if it's sql server database and there's a identity column(which is in sequence) , then we can make use of the below query:

Code: Select all


DELETE FROM table_name WHERE IDENTITY_COLUMN=3

That's why i have raised that question.

Thanks
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Still, doesn't matter. Having an "identity column" (or any other surrogate value) with a 3 in it doesn't make it "the third row". It's not sequential media, after all.

That's not to say that based on very specific conditions and/or sort orders, you couldn't identify the third record in the result set. But in the table? No such thing. Like I said, a trick question. And they've already specified it is an Oracle database.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's no such thing, for a user, as the third row in a table. The mechanism by which rows are stored in a table, are entirely the province of the database server.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

Third row in a table as such doesn't mean anything, however a question should be asked back like, on what basis you identify which is the third row. like based on date or some other sort key.. then rank() function comes in handy to get the third row.

But still there is no answer to the question asked in first post as it is.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

Let KEY_1 is ur PK(or any distinct column) and ABCD is your table,
then this might help

delete from ABCD where key_1 in
(select key_1 from (
select key_1 from ABCD
fetch first 3 rows only)
order by 1 desc
fetch first row only)

@everybody
For every Question there's an answer. :P
Thanx and Regards,
ETL User
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Chandra ,

based on some assumptions, you have prepared the query(PK,order by desc).
But the owner of this question din't provide all those details.
pandeeswaran
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

@pandeesh
I know what you are trying to say, but the bottomline is that the query works. :)
Thanx and Regards,
ETL User
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

... but does not necessarily delete the third row from the table.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

priyadarshikunal wrote:But still there is no answer to the question asked in first post as it is.
Ah... but there is, and it has been answered. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

seems tit for tat kind of solution... you didn't give me the condition, i deleted the 3rd row encountered. You can't blame me if you didn't wanted to delete that record. :wink:
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Post Reply