473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to update the status of a particular row as 1 if the whole record already exists?

Hiii,
I have data like a sbelow.

emp_id name marks status
1 raga 23 null
1 raga 23 null

There is no primary key for the table.

Now i want the result like
1 raga 23 1----only for the first record
Apr 3 '13 #1
2 1692
vijay2082
112 100+
Hi,

Use below login to do this. Use update and the construct in place of delete.

First way
==========
[myserver::db2inst1::/home/db2inst1] db2 connect to sample
db2 "crea
Database Connection Information

Database server = DB2/AIX64 9.7.6
SQL authorization ID = DB2INST1
Local database alias = SAMPLE

[myserver::db2inst1::/home/db2inst1] db2 "create table test(srno int,name varchar(15),location int,address varchar(10))"
DB20000I The SQL command completed successfully.
[myserver::db2inst1::/home/db2inst1] db2 commit
DB20000I The SQL command completed successfully.

[myserver::db2inst1::/home/db2inst1] db2 "insert into test values(1,'raga',23,NULL)"
DB20000I The SQL command completed successfully.
[myserver::db2inst1::/home/db2inst1] db2 "insert into test values(1,'raga',23,NULL)"
DB20000I The SQL command completed successfully.
[myserver::db2inst1::/home/db2inst1] db2 commit
DB20000I The SQL command completed successfully.
[myserver::db2inst1::/home/db2inst1] db2 "select * from test"

SRNO NAME LOCATION ADDRESS
----------- --------------- ----------- ----------
1 raga 23 -
1 raga 23 -

2 record(s) selected.

[myserver::db2inst1::/home/db2inst1] db2 "select rowid,test.* from test"

1 SRNO NAME LOCATION ADDRESS
----------------------------------- ----------- --------------- ----------- ----------
x'000000000000000400000025840101AC' 1 raga 23 -
x'000000000000000500000025840101AC' 1 raga 23 -

2 record(s) selected.


[myserver::db2inst1::/home/db2inst1] db2 "delete from test where rowid=x'000000000000000400000025840101AC'"
DB20000I The SQL command completed successfully.

[myserver::db2inst1::/home/db2inst1] db2 commit
DB20000I The SQL command completed successfully.

[myserver::db2inst1::/home/db2inst1] db2 "select * from test"

SRNO NAME LOCATION ADDRESS
----------- --------------- ----------- ----------
1 raga 23 -

1 record(s) selected.



Second way
==========


[myserver::db2inst1::/home/db2inst1] db2 "select * from test"

SRNO NAME LOCATION ADDRESS
----------- --------------- ----------- ----------
1 raga 23 -
1 raga 23 -

2 record(s) selected.


[myserver::db2inst1::/home/db2inst1]db2 "select SRNO,NAME,LOCATION,address,row_number() over(partition by SRNO,NAME,LOCATION) as row_num from test"

SRNO NAME LOCATION ADDRESS ROW_NUM
----------- --------------- ----------- ---------- --------------------
1 raga 23 - 1
1 raga 23 - 2



[myserver::db2inst1::/home/db2inst1]db2 "delete from (select SRNO,NAME,LOCATION,address,row_number() over(partition by SRNO,NAME,LOCATION) as row_num from test) where row_num=2"
DB20000I The SQL command completed successfully.

[myserver::db2inst1::/home/db2inst1] db2 "select * from test"

SRNO NAME LOCATION ADDRESS
----------- --------------- ----------- ----------
1 raga 23 -

Cheers, Vijay
Apr 5 '13 #2
vijay2082
112 100+
to be more precise on update, below will work for you.

[myserver::db2inst1::/home/db2inst1]db2 "update (select SRNO,row_number() over(partition by SRNO,NAME,LOCATION) as row_num from test) set srno=2 where row_num=2"
DB20000I The SQL command completed successfully.
[myserver::db2inst1::/home/db2inst1] db2 "select * from test"

SRNO NAME LOCATION ADDRESS
----------- --------------- ----------- ----------
1 raga 23 -
2 raga 23 -

2 record(s) selected.


Cheers, Vijay
Apr 5 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ondernemer | last post by:
I looked everywhere (Google, manual, etc.) but can't find an answer to this question. If I do a "INSERT IGNORE INTO" query into a UNIQUE field and the word I'm trying to insert already exists,...
4
by: Jim in Arizona | last post by:
I'm wanting to do a simple controlled voting page. I too our webserver off anonymous and everyone who accesses the website is a domain authenticated user. I've already done some control structure...
6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
2
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
2
by: kkleung89 | last post by:
Basically, here's what's happening with the program. I have a table of Customers and a table of Pets, with the latter containing a field linking it to its customer of ownership. I have a form...
1
by: delusion7 | last post by:
Trying to create a table and insert records from a webform and I keep getting this message: "Successfully created the registration table. Unable to execute the query. Error code...
3
by: byeung | last post by:
Hi, I am trying to check if a particular record already exists in an Access database through Excel vba code. Through code obtained at another forum, I got the following: ...
6
by: deejow | last post by:
Hi, I want Access to return an error message that says an identical entry already exists. I do not want to set the field to 'no duplicates' because it is a name field and it is possible to have...
1
by: Roland | last post by:
Hello, I am writing modal dialog box to display progress of downloading file. I am starting download of a file in constructor of dialog using some asynchronous method call which returns me an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.