Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Update Table With Info In Other Table


i have a case like this:

table table1 (key, accumulator)

table table2 (key, counter)

i want to, for each table1.key = table2.key, update accumulator with the info in counter, something like this:

update table1 set accumulator=accumulator+table2.counter where (? counter is the value related with the same key as the one in table1)

how do you write a sentence like this one?




View Complete Forum Thread with Replies

Related Forum Messages:
Selecting From A Table Based On Info In Another Table
Essentially this is what i want to do. I have two Tables,

Table A- has the field "id" which is the primary key
Table B- has the field "id" which is the primary key


Select * from tableA where Table A.id is not in tableB.id


How can i form a statement that will accomplish the above.

View Replies !
Table Based On Info In Another Table
Essentially this is what i want to do. I have two Tables,

Table A- has the field "id" which is the primary key
Table B- has the field "id" which is the primary key


Select * from tableA where Table A.id is not in tableB.id

How can i form a statement that will accomplish the above.

View Replies !
Info Into Table
I have made this site http://www.tinemuller.dk/folkebiblioteker/ and used mysql and have a lot of columns but what I need help to is "hjemmeside" which at the moment is empty for all the libraries (name).

I have now found a excel-file where I have deleted all the columns that I shouldn't use and only left "name" and "hjemmeside" and name is identically with name in the database online.

How do I get my database updated with the informations in "hjemmeside" from the excel-file and at the right place in the row of the right "name".

View Replies !
Getting Info From More Than One Table
ok so Ive normalised my database, and all is good, ro repeating data anywhere.

Now.....I'm a bit stuck

I have an invoices table, a jobs table, and a customers table.

invoices
=====
invoiceref - integer primary key autoincrement etc
jobref - this leads to the job details
invtotal - the total for the invoice

jobs
====
jobref - integer primary key etc
customerid - the customers id number
other - misc colums of job details not relevant to this question

customers
=========
customerid -primarykeyetc
custname -customers name
other - other fields , address tel etc

ok so i need to display invoice details like this

Invoice Number Customer Name Job Number Invoice Total

Three of the columns are no problem, just select * from invoices
But how do i write a query that will look up the job for the invoice, check the customer, and bring me the customers name too?

A cheap shot solution would be to have the customerid field on the invoices table too, but then that would not be fully normalized as we already can get that information from the job the invoice is linked to.

View Replies !
Rename Table Info
i have a table that is built like so...
id,game,score,genre,system,year,reviewer,console_id

125,'Aztec','','Puzzle','Neo Geo Pocket Color,1998,'',1


i want to make all entries of "Neo Geo Pocket Color" to be "NGPC"...
what kind of command could i exacute to do this... i know how to rename a column... but not table info...

View Replies !
Double Table Info
I'm a newbie setting up a PHP-MySQL database and I'm just at the table creation stage. I'm worried because I have two tables that are showing the same info so I wonder if my database is truly normalized... Here are the tables I am worred about... so far:

-Instructor-
InstructorID
iFirstname
iLastname
iEmail

-Student-
StudentID
sFirstname
sLastname
sEmail

-Instructor_useraccount-
Instructor_useraccountID
InstructorID
iPassword
iPriviledge
iActivationDate
iExpiryDate
iLastaccess

-Student_useraccount-
Student_useraccountID
studentID
sPassword
sPriviledge
sActivationDate
sExpiryDate
sLastaccess

I'm wondering if I can one "USERAccount table" and add a foreign key of USERID to both the Student table and the Instruction rather than the way I've done it.

View Replies !
Change Table Info
does enyone know if this is possible in some way without first get the information

UPDATE test SET `bbbb`=`aaaa`, `aaaa`=`bbbb`

i don't want to select the information first in issue of server load!!

View Replies !
Can I Edit Table In One Db With Info In Another Db?
Can you update a database table from another database?

View Replies !
Adding Info To Table
I have a current list of names in a table and I am trying to add another list to it without duplicating the names. is there a way to do something like this?:

"INSERT INTO master_list VALUES ($namefromnewlist) if $namefromnewlist IS NOT IN master_list"

View Replies !
Getting Info Out Of A Table, And Formatting It.
i have a table containing a bunch of rows.

Format of the table is

id name

and in the table i have things like:

1 Photoshop
2 Flash
3 PHP
4 CSS
5 HTML

etc, what i want to do, is get them out of the table, and format them to be like this:

<li class="brdmenulinks">Photoshop</li>
<li class="brdmenulinks">Flash</li>
etc...

in the order of there id.

View Replies !
INSERT Into New Table, SELECT From Old Table, UPDATE Old Table With New Key
Code:

INSERT INTO retailers
(retailername, retailerdesc, retailerwebsite, retailerurl, active)
SELECT
datasource_retailername,
datasource_retailerdesc,
datasource_retailerwebsite,
datasource_retailertrackurl,
1
FROM
datasources_retailers_idx AS i
LEFT OUTER JOIN
retailers AS r
ON
r.retailername NOT REGEXP REPLACE(i.datasource_retailername, ' ','.+')

UPDATE datasources_retailers_idx SET idretailers=last_insert_id();

Here's what I'm trying to do:

* Select from old table
* check if there is a matching retailer in the new table
* If not, insert retailers details into new table
* Update a reference column in the old table with the INSERTID primary key value of that row from the new table

View Replies !
Selecting Info Depending On Another Table
I have a web page where users enter their email address to be added into a table (for a future newsletter) however, if they become a member (which is another table) i don't need the email anymore. Now to make it more simple, I don't need to do an UPDATE query.

What i'm going to do is create another page that'll show the list of emails from the newsletter table, except the duplicates from the members table.

i guess something like this

SELECT newsletter,member WHERE newsletter.email != member.email

Does it make sense?

View Replies !
Exporting Table Build Info
What is the command that puts into a string the sql queries that would be required to build a table?

View Replies !
Lookup FK Info On MyISAM And InnoDB Table
I'm wondering if there is a way to retrieve Foreign Key declaration
information on both MyISAM and InnoDB tables.

Of course, I understand that MyISAM doesn't support Foreign Keys,
however, it does still parse FK declarations within a CREATE TABLE
statement, and moreover, it even creates an index on the column that
is the Foreign Key.

So my question is for this sample CREATE TABLE declaration:

CREATE TABLE table_name (
id INT NOT NULL AUTO_INCREMENT,
other_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (other_id) REFERENCES other_table (id))
TYPE = InnoDB --- OR --- TYPE = MyISAM
;

Can I get the Foreign Key information (meaing, the table and the
column that a FK is keyed to) from MySQL?

Doing a "DESC table_name" or "SHOW KEYS FROM table_name" indicates
that the FK column is Indexed, but doesn't really give much more
information other than that.

The only way I seem to be able to get *some* sort of FK info is if i
do a "SHOW CREATE TABLE table_name" (and even so, this only works on
InnoDB tables. For MySQL tables, it will show my foreign key
declaration as just a simple index).

View Replies !
Changing The Info In A Table With Multiple Index Columns
I have a MySQL question about changing the info in a table:

I am using MySQL Server version: 3.23.58

I have a table called sign_region2 and it contains thousands of
references to signs and the regions they are in.

mysql> desc sign_region2;
+-----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| id_sign | int(11) | | PRI | 0 | |
| id_region | int(11) | | PRI | 0 | |
+-----------+---------+------+-----+---------+-------+

This table keeps track of which signs are in which regions. Note that
the Primary Key is a multiple-column index (id_sign and id_region).

mysql> select * from sign_region2 limit 20;
+---------+-----------+
| id_sign | id_region |
+---------+-----------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 2 | 4 |
| 3 | 5 |
| 4 | 5 |
| 5 | 5 |
| 6 | 5 |
| 7 | 5 |
| 8 | 2 |
| 10 | 2 |
| 11 | 1 |
| 11 | 2 |
| 11 | 3 |
| 11 | 4 |
+---------+-----------+
20 rows in set (0.00 sec)

I need to take all "id_region = 4" and make them "id_region = 2"
except where "id_region = 2" already exists. In that case I'd just
need to delete where "id_region = 4".

Remember that there are thousands of references in this table. Some
signs are in region 2, some are in region 4, some both, some neither.
What query would I use to accomplish this?

The problem is that the DB won't allow identical instances of the
id_sign and id_region combinations (because they must be unique
because they are primary keys).

An example:
Let's say I've got a table that looks like this...
+---------+-----------+
| id_sign | id_region |
+---------+-----------+
| 12 | 1 |
| 12 | 3 |
| 12 | 4 |
| 12 | 5 |
+---------+-----------+

But I need it to look like this...
+---------+-----------+
| id_sign | id_region |
+---------+-----------+
| 12 | 1 |
| 12 | 2 |
| 12 | 3 |
| 12 | 5 |
+---------+-----------+

But for thousands of records not just the ones with "id_sign = 12".

View Replies !
How To Find Total No. Of Records In A Table Having Same Info In Some Fields?
i just want to find out total no. of records in a table which is having same information in some fields of table mean matching information in the fields. i can elaborate it as suppose i have a survey table which is having 4 answers fields and there are thousands of records in that table, i want to know how many people have given same answers.


View Replies !
Update Table Based On Email In Another Table
I'm having trouble updating the entries from a table. The situation is as follows:

Customer table contains:
1) customer_email_address
2) customer_newsletter (value 0 or 1)

Visitor table contains:
1) email

The visitor table contains email addresses from customers that have signed up through another system.

I would like to update the customer table and set customer_newsletter to 1 where customer_email_address matches email from the visitor table.

View Replies !
Update A Table With Data From Another Table
I have two tables with similar data. The firs table contains data that is to be updated with data from the second table. The first table (tblA) has a unique key, but the second table (tblB) does not.

I have to use the 'lastname', 'firstname' and 'dept' fields that are in both tables and join the tables on those three fields.

I have tried:

update tblA, tblB
set tblA.empPty=tblB.empPty
where ((tblA.empLName=tblB.empLName)
and (tblA.empFName=tblB.empFName)
and (tblA.empDept=tblB.empDept));

with some test data where I know I have a match using the three fields, but nothing gets updated.

View Replies !
Update One Table Value With Values From Another Table
I am trying to update one table value with values from another table, and I cannot get it to work. What am I doing wrong?

This is my SQL-command:
UPDATE tabel1 SET tabel1.name=tabel2.name WHERE tabel1.ID=tabel2.ID

View Replies !
Dumping Data :: All Table Columns Info And Rows Of Data
Is there anyway to dump all the tables columns info and rows of data? Like you can with phpmyadmin, but just without using it :P

I have afew tables on my old desktop that i never saved the table info of and can't be arsed retyping it :P plus i wanna keep all the data of course

I tried installing phpmyadmin on it ages ago, but it ****ed up (which in turn was a good thing 'cause it forced me to learn to do things properly without the help of that), so yer...

View Replies !
Table Design Question? House Table, Owner Table, Code Violations Table - Best Way?
Given the tables:

HOUSE
house_ID
address

OWNER
owner_ID
name
telephone...

HOUSE_OWNER_JOIN
?

CODE_VIOLATION_HISTORY
house_ID
violation_ID
violationStatement
...

My goal is to be able to track code violations of the house PER owner.

For example, I need to display a page that shows the current house with it's coe violations and a link to show the HOUSE's history of violation regardless of owner, Like:

House 1009283
Address
Past history (link to the following)

House History
2001-01-04 Owner: John Smith Code Violation: Gutter issue
1999-06-01 Owner: John Smith Code Violation: Faulty Steps
1998-03-02 Owner: Sam Spade Code Violation: Driveway carcks
1990-01-12 Owner: Keith Sledge Code Violation: Grass untidy


For the design of the HOUSE_OWNER_JOIN table, I thought of two ways I could go on this and this is where I need your help.

Option 1:
Have the HOUSE_OWNER_JOIN table keep dates so I can track the ownership changes that way:

HOUSE_OWNER_JOIN
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

then I could look up all code violations by date and associate them with their rightful owner.

==================================================
Option 2:
Have the HOUSE_OWNER_JOIN table be the primary keeper of identity data by adding a new primary key and changing the CODE_VIOLATION_HISTORY table to reference that table by chaning the referencing key from house_ID to house_owner_ID:

HOUSE_OWNER_JOIN
house_owner_ID
houseID
ownerID
dateOwnershipBegan
dateOwnershipEnded

CODE_VIOLATION_HISTORY
house_owner_ID
violationStatement
...

View Replies !
Update Table From Another Table
I have 2 tables: country and ticket

country table contains countryId and countries

ticket table contains many fields, and a country field

the country table is new and consists of all countries to be used in a drop down on the ui, that is joined with the ticket table to display the correct country based on the id.

that being said.. the current ticket table also contains a country field which will be eliminated in the future. what I want to do is update the ticket table by finding the closest match to ticket.country in the countries.country table and then update the ticket.countryId to the countries.countryId.

This is what i have been doing country by country:
Expand|Select|Wrap|Line Numbers

View Replies !
Update Table With API
I'm trying to develope a getway between matlab and mysql. I would like to
write the result of matlab routine into mysql table without "UPDATE
.....SET..." statement, because I've have to write a different value for each
row and I have to write a lot of row. I would like to write table row by row
sequentially.



View Replies !
2-table UPDATE
I am running the following query through PHP's mysql_query:

UPDATE hotel, hotel_brand
SET hotel.hotel_brand_id=0, hotel_brand.hotel_brand_parent_id=0
WHERE hotel.hotel_brand_id=6 AND hotel_brand.hotel_brand_parent_id=6

In actuality, it's two queries combined into 1. I am deleting a value that rows in these 2 tables reference, and want to set the values to 0.
Of course, the problem is the values aren't changing to 0.

Is splitting these up the best solution?

View Replies !
Update Table From TXT/CSV
I have a table With Field1(INT,8,PK), Field2(INT,6,PK), Field3(VARCHAR,255) and Field4(VARCHAR,255).

I have to update records from a FIXED LENGTH TXT that contains:
Field1(8 digits)Field2(8 digits)Field4(1-255 digits) or the same in CSV....

View Replies !
UPDATE Table SET
Does anyone know how to implement this into a php form CORRECTLY? I have all the proper syntax but then the server gives me a message that says the mysql version may not go along with the syntax. How do I work around this then? I need to update query strings and such and nothing will work.

View Replies !
UPDATE From One Table To Another
This should be so simple but I'm getting a very strange error??

I'm using MySQL version: 4.1.12-log

I've got an outdated country table that I'd like to update info from an ISO table. Pretty straight forward if you ask me.

Here's the query:
UPDATE country, isocountry SET country.un_numcode=isocountry.numcode
WHERE country.country_code=isocountry.iso;

I created a column called un_numcode and then I'd like to put the iso numcode info in my table where the country_code = iso code (same data, different field names in different tables).

It goes along really well for 38 rows out of 239 rows?? And then I start getting 127 in ALL the un_numcode fields even though that value does NOT exist in the country.numcode table!

View Replies !
Update One Table
I have 2 tables one for the team standings one for the scores, this select statement will calculate win loss :

SELECT
SUM((homescore>awayscore and home=teamid)
OR (awayscore>homescore and away=teamid)
) as wins,
SUM((homescore>awayscore and away=teamid)
OR (awayscore>homescore and home=teamid)
) as losses
FROM scores, teams
order by teamID

View Replies !
Table Update
How do I relate such a way that I update a column of the main table, another secondary table's column related to the main table gets updated automatically?

View Replies !
UPDATE From A Linked Table
I wanna update the table COMPANY from a linked field. The following is not
accepted. Could anybody help me with what the command should be?
Thanks a lot.


UPDATE `COMPANY`
SET `COMPANY`.Region_ID =
(
SELECT `Area`.Region_ID
FROM `AREA`
WHERE `COMPANY`.Area_ID = `Area`.Area_ID
)

View Replies !
Update A Table With Values In Another
I have the following table

tableA
column_a
column_x
column_y
column_z

tableB
column_x
column_y
column_z

How do I update the rows of tableA that match rows of tableB (all rows
of tableB are unique)

What I want to acheive is a check against tableA.column_x with
tableB.column_x, if they match, then update the row in tableA.column_y
with the value of tableB.column_y and tableA.column_z with
tableB.column_z

View Replies !
Update Table By ID Ranges
How do i use the UPDATE statement to update a range of Primary Key id
numbers. (let say 100 through 1000).

Example,

UPDATE testTable set testField='9999' WHERE
test_id in (100:1000);

View Replies !
UPDATE Based On Value In Another Table
How do I update a table to remove orphaned references to a second table? I've deleted rows in the second table, which has a unique auto_increment key. The first table now has references to keys that no longer exist. I need to update the first table, setting the value to NULL where the referenced key no longer exists. Something like:

UPDATE table1 SET table2ID = NULL WHERE table1.table2ID NOT FOUND IN
table2.ID;

The NOT FOUND IN isn't SQL, of course, but I'm not sure what should go there.

View Replies !
Automatic Table Update
i have an database in which i need to update a status filed of an table with the date.

i,e those datas which gets expired are to be updated..

so need to run a command in mysql by default.,

View Replies !
Multiple-table UPDATE.
I'm trying to update multiple-tables at the same time but I read somewhere that you could do it if you had mysql version 4.0.4. But currently, I have version 4.0.0 and I want to know how to do it with this version

View Replies !
Update Table Problems
I'm trying to update a table where specific values are in another table. Here is the update statement I am using:

UPDATE Route_Detail,Routes SET Route_Detail.Trip_Calc='S'
WHERE Routes.Route_ID = Route_Detail.Route_ID
AND Routes.Project_Code = 'OSUT'
AND DATE_FORMAT( Route_Detail.R_Date, '%m%Y' ) = 072006

This statement runs but does not update any rows.

This select statement returns 11 rows:
SELECT RDetail_ID
FROM Route_Detail
INNER JOIN Routes ON Routes.Route_ID = Route_Detail.Route_ID
WHERE Routes.Project_Code = 'OSUT'
AND DATE_FORMAT( Route_Detail.R_Date, '%m%Y' ) = 072006

How do I get the UPDATE statement to update those 11 rows.

I'm using MySQL 4.1.21-standard version.

View Replies !
Fields In Table Will Not Always Update,
I'm using C#, ASP.NET and MySQL, The language is no problem (not to much) but the rest well I wonder. I have a DB table that has 5 seperate fields. A main one that
is Integer and the rest are VarChar(50). each of the 4 others are identical in setup. I can change some records and others I can't.

ID int(10),
std varchr(50),
atd varchr(50),
dtd varchr(50),
ctd varchr(50)

I update say 'atd' with new data, Date, Time and a code of 15 letters/numbers.This one takes, I change to another record and try to update ctd and it shows like it takes but when I use the Command Line it shows no updates on ctd. this is random on this also.
If I change to another record it may all work or not. Any Ideas at all?

View Replies !
Update Table With Java
im trying to update my table bunt

int test=5;
String update="Update bunt SET buntnr='test' Where bunt_ID ='ver.bunt_ID'";

wich results in this error

Data truncation: Out of range value adjusted for column 'buntnr' at row 1

If i use this, changing variables to ínt it works fine!
String update="Update bunt SET buntnr=5 Where bunt_ID =1";

View Replies !
Update Based On Another Table
Is it possible to do an update in MYSQL based on another table? I have version 3.23 and when I try to run this statement:


UPDATE ApplicationTbl
INNER JOIN AcademicTbl
ON ApplicationTbl.CampusID = AcademicTbl.CampusID
AND ApplicationTbl.Application_Period = AcademicTbl.Application_Period
SET ApplicationTbl.App_Status = 'Qualified'
WHERE AcademicTbl.Sem_OnCampus >= '1'
AND AcademicTbl.GPA >= '2.4'
AND AcademicTbl.Judicial_Sanction IS NULL

It keeps saying its wrong. Even though I know its not

View Replies !
Update Records In Table
i have installed a mysql server, and i have a problem with import record in database.
the origine is a file txt or csv, the destination database contain also other records, and i must update the records into database

View Replies !
Update Table Values
I have a csv.txt file with contacts and their information in it. Then I also have a table in mysql with the same contacts and their various information. I need to merge these to so that if a field value in the database is NULL the value that is in the csv.txt file is inserted into the database field.

I have been looking at the mySQL site on how to do this but have not been able to produce a working solution. Below is a more detailed example of what I am looking for. Code:

View Replies !
Very Slow Table Update
I have two tables. One is really a subset of the other. However, they came in different data files and I would like to pull data from one and put it into the other. However, it is VERY slow!

Once the tables are setup I will only read from them and perform operations. I will never update or insert. However, I can't get things setup to that point. Code:

View Replies !
Update Table From File
I've a file with 6000000 UPDATE commands.

I'm planning to execute those commands on BANKING database using:
mysql banking < update_table.txt

Is this the best way to execute many updates on the database, without affecting performance?

I'm worried to overload the BANKING database with those long updates...
What do you think about it?

View Replies !
UPDATE A Table, Using GROUP BY
I have a table with the following fields --

schoolcode (e.g., 313)
teachername (e.g. JONES)
studentname (e.g., JOHNNY DOE)
totaltestitems (e.g., 50)
totalitemscorrect (e.g. 40)
studentpctcorrect (e.g., 80.0)
teacherpctcorrect (????)

(NOTE: schoolcode + teachername combination would be unique.)

I want to UPDATE the table with the average percent of items correct for students assigned to each teacher (teacherpctcorrect).

View Replies !
Update Count From Another Table
I am trying to write a query that takes the count() from one table and updates a second table with the value.

This is what I have so far:

UPDATE wp_posts SET wp_posts.comment_count = SELECT count(comment_ID) as comment_count FROM wp_comments where wp_comments.post_ID = wp_posts.ID

What am I doing wrong?

View Replies !
Daily Update Of A Table
I've a MySQl db.
I've a table "example", with 3 columns:

code::int
date:date
status:bool (0 or 1)

I need each day something checks my table and calculates difference between current date and date in the second column of my table. ....

View Replies !
Update, Table Locking
Is it possible to have update in a iterative loop with start index and range wtih the query? I wouuld like to have the update happen in steps with loop to avoid getting the entire table locked.

Also, I do fine the query takes around 10.88 secs to update to complete. this is one reason i prefer to have update happen in steps so that entire table locking do not happen.
its innodb table.


View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved