473,556 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replicating values in a table

I have a table that contains mostly zero entries but has a few
non-zero values scattered randomly in the table as VERSION 1 below.
What I want to do is fill in the zeroed values with copies of the
non-zero values resulting in the modified version of the table as
shown in VERSION 2 below.

In other words, I want to replicate entries following the entries as
originally supplied.

I would like someone to supply me with the MySQL code that can do this
or point me at an example of it.

CREATE TABLE `table1` (
`record_number` int(8) NOT NULL auto_increment,
`field_A` int(11) default NULL,
PRIMARY KEY (`record_number `),
UNIQUE KEY `record_number` (`record_number `)

1 0
2 0
3 0
4 99
5 0
6 0
7 0
8 0
9 33
10 0
11 0
12 0

1 0
2 0
3 0
4 99
5 99
6 99
7 99
8 99
9 33
10 33
11 33
12 33

Thanks very much for your help.
Jul 20 '05 #1
1 1483
James E Koehler wrote:
I have a table that contains mostly zero entries but has a few
non-zero values scattered randomly in the table as VERSION 1 below.
What I want to do is fill in the zeroed values with copies of the
non-zero values resulting in the modified version of the table as
shown in VERSION 2 below.

How about pseudocode:

SELECT record_number, field_A
FROM table1
WHERE field_A != 0
ORDER BY record_number DESC

Loop over result set of above query:
UPDATE table1 SET field_A = ?
WHERE field_A = 0 AND record_number > ?

Provide the values from the current record in the loop as parameters to

You may have been hoping for a complex update statement that would do
the whole thing, but I can't think of one. Sometimes it's better to
make use of a programming language to help you out.

Bill K.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Nathan Simpson | last post by:
Hi, We have one domain with a mixture of NT PDC's one Win2K DC (which was the first installed) and 4 Windows 2003 DC's. I created our sites as per MS documentation and created the subnets that match each site. I moved each server into its own site. I then create the Inter-site transport with IP. I create one call "All Sites" and copied...
by: Justin French | last post by:
Hi all, I've been using CSS for typography for quite some time, but have not looked into it too deep at all in regards to layout. Now is as good a time as any eh? Whilst ultimately I'll want to look at complex layouts (and can find plenty of tutorials on them already), I just want to start with the basics for the moment...
by: nwiebe | last post by:
Hi, does anyone know how to avoid replicating delete statements? I have a table in a source database. This table is pruned occasionally. I'd like to have a copy of this table in a second database, containing every row that ever existed in the source table. So, when a "delete from srouce where ..." is execute, that delete is not...
by: Derickson | last post by:
I am working with a production runtime Access 2000 db, split front-end and back-end. Running on a network, I need a nightly copy of the backend transferred to a laptop with a temporary network connection so as to be able to run a locally linked version of the database outside of the production environment. No data will be modified; it will be...
by: bissatch | last post by:
Hi, I have an HTML structure where each page area is a <div> and identifies with a unique 'id'. Below is the code: <html> <head> <style> #wrap {
by: ceadtinneh | last post by:
We're running merge replication between to SQL Server 2000 servers. The application isn't very high volume the setup is pretty vanilla (ie no filters, etc). We have a push subscription set up and we seem to replicating data between publisher and subscriber, with one exception: When we update a particular int column at the publisher, the...
by: Radek | last post by:
Hi I'm in need of creating reporting database. What I have to do it is to replicate only half of tables to next database so reports could query only that second database. Unfortunately there is too many inserts in existing database so simple master/slave solution won't give me much. I was wondering if there is a way to replicate just few...
by: war_wheelan | last post by:
I am replicating an 80GB database between NY can CT and would like to know why table sizes are different between the two. Here is an example of sp_spaceused:: NY IOI_2007_04_23 rows(279,664) reserved(464,832) data(439,960) index_size(24,624) CT IOI_2007_04_23 rows(279,666) reserved(542,232) data(493,232) index_size(48,784) ...
by: aswath | last post by:
hi dere, i have a question. i have an array with replicating values.... al i want to do is delete all replicating values and store the result in another array. eg., String a={1,2,3,3}; String b; b should be 1.2.3only........not 1,2,3,3 thanks in advance, regards,
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.