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




Update Table From Temporary Table


I have an import process that creates a temporary table and then dumps a large amount of records into it. I need to update an existing table against this temporary table. So where the record exists I either want to update or replace (probably based on parameter but can be a separate query for each) it in the live table, and if it does not exist i want to add it.

The temporary table can contain a large number of records (100000-200000). How can I create a fast and efficient process for doing this? Is there a query I could write to do this or would I have to do this through through code (i'm working in a java environment). I think a query would be faster than processing that many records via jdbc.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Not Unique Table/alias: <tablename> For Temporary Table
I’m converting an application from Paradox to MySQL (first time I’ve used this) and am replacing Paradox local tables with MySQL temporary tables – I understand each user will have a unique copy of the table. Basically I issue the following two commands :

'drop temporary table if exists <tablename>'

'create temporary table <tablename> like <tablename>'

where <tablename> is a table structure in the database with 0 records. This strategy was successful while I was working with a local copy of MySQL on my development PC, but when I run the system from a server on the office network I get the following error :

#42000Not unique table/alias: <tablename>

The environment I work in is Windows XP Pro SP2, Delphi 5 and CoreLabs MyDAC data access components. I’ve searched this site and Googled to no avail. Hoping someone has seen this before.

Temporary Table Or Append Master Table
I am using PHP to interface to MySQL. After PHP provides the user inputted data, MySQL will perform several queries using both the user data as well as several other non-user specific tables, and return the resultant values which PHP will return to the user. Multiple users will access the system simultaneously. I know of two possible solutions, but don’t know which is better.

I can either create a table called T_USER_DATA (there will actually be 6 tables, some with one row per user and others with multiple rows) with a column for C_USER_ID, and additional columns for the user’s data. The user data rows will be added, and then filtered based on the USER_ID.

Or, I can create a temporary table (maybe using a memory engine for faster speed?) specific for a given user on the fly when PHP passes the data. The queries are performed, data returned to PHP, and then the temporary table is deleted when the connection to MySQL is closed.

Temporary Table
I want to create a temporary table and I get the following error
message :

mysql> CREATE TEMPORARY TABLE tempemp AS SELECT * FROM emp;
ERROR 1044: Access denied for user: '@localhost' to database 'test1'

Code:

Temporary Table
Here's what I'm trying to do.  First, I have a table like this:
___________   ________   _____   _____
[prime_key] [Field_ID] [Field] [Class]
 ---------   --------   -----   -----
         1         1A   'foo'     'A'
         2         2A   'bar'     'A'
         3         1A   'tst'     'B'
         4         3A   'hi.'     'B'

Temporary Table
I'm having a problem with MySQL on our webserver. The problem is that I keep getting #1036 errors, 'Table '#sql_xxx' is read only'.

For example:
--------------------------------------------------------------
Error which occured on 10:36:31 AM:
Query:
SELECT * FROM tablename WHERE id = '118' AND status != '3'
Error:
Table '#sql_1564_0' is read only

Error which occured on 10:37:43 AM:
Query:
SELECT * FROM tablename WHERE id = '118' AND status != '3'
Error:
Table '#sql_1564_0' is read only
--------------------------------------------------------------

It seems to me that this error occurs when multiple users are trying to select data from the same table. MySQL tries to use the same temporary table.

Using Temporary Table
I have added a search function to a mysql database that creates alot of results. My plan was to use a temporary table to store the results and then display (using php and html) them 10 per page. This works great on page one, but then when I move on to the next page I get an error because the temporary table no longer exists.
I pagiate by first getting a count of the resultset and then passing on a variable for the limit.

Temporary Table
the temporary table does not return results but the select statement on its own does:
Code:

CREATE TEMPORARY TABLE t2 AS SELECT CONCAT("<a href=
"javascript:NewWindow('live.aspx?
sid=70','mypopup','1024','768','center','front');"><u>",s.title,"</
u></a>", LEFT(CONCAT('<p>',s.Description,'</p>'), 100)) AS Events,
c.StartDate As Date,
c.ScheduleType As Type,
c.ScheduleType As Status,
p.DisplayName As Presenter
from CommonSchedule c
inner join schedulemetadata s on (c.ScheduleID = s.ScheduleID)
inner join presenter p on (c.ScheduleID = p.ScheduleID);

What am I doing wrong? How do i construct this as a temp table?

Temporary Table
I think I know the answer to this question, but just to make sure. Temporary tables are dropped as soon as the connection is closed.The connection refers to the mysql connection as oppossed to a SESSION? So if I wanted to preserve data for a user within their session, but delete it as soon as their session ends, temporary tables probably would work for me?

Temporary Table
im looking to use a temporary table that acts more like a SESSION variable does in php. i use other temp tables in the site im working on and they go away after the sql connection is closed at the end of the page. i was wondering if theres a way to create a table that is there for a certain time period, or the best would be, like i said earlier, to act almost exactly like a session variable.

Temporary Table Does Not Exist
I've had this code running for over a year and now, all of a sudden, it no longer works.
I'm using PHP and MySQL 3.23.58 which my host provides. Code:

Create Temporary Table
When I try and run the following query

create temporary table russ1 as

select rcust.*

from rcust;

and I receive the error message:

Error Code : 1044

Access denied for user: 'russ@192.168.1.79' to database 'customer'

(0 ms taken)

I can run the query from the command line of the server and the query
works correctly.

I have run the query GRANT ALL PRIVILEGES ON customer.* TO
russ@192.168.1.79

In addition, I flushed the privileges, and I stopped and restarted the
database.

Temporary Table Error
I was surprised to get this error when playing with temporary tables:

mysql> use test;
Database changed
mysql> create temporary table t (i int);
ERROR 1049 (42000): Unknown database 'test'

I am using WinXP with MySQL version14.7 Distrib 4.1.21 - mysql-max

Does anyone know why I can't create a temp table? This happens with any database I select.

Temporary Table On MySQL
Does anybody know how to create a temp table on MySQL without creating it on the database?

in MS SQL it has something like:

select ...
into #T1 -- this is a temp table
from ...

then, I want to call this #T1 later on the same query window.

Is there an equal command in MySQL?

Temporary Table Is Full
During executing SELECT query, MySQL creates disk temporary table.
After the tabe exceeds 4GB I get table is full error.

How can I change settings to remove 4 GB bareer from disk tmp tables?
It is easy to set in phisical MyISAM table by increase MAX_ROWS.

Cannot Create Temporary Table
I cannot create a temporary table. What am I doing wrong?

CREATE TEMPORARY TABLE UMB.SRC_TMP
Select * from SRC_TMP limit 10;

Select count(*) from UMB.SRC_TMP;

table 'umb.src_tmp' doesn't exist.

Temporary Table Performance
Since I work with MySQL 4.0... I can't use sub queries.
So I have to create a temporary table to perform a complex request.
The request has to be called periodically (let's say every second).

The data in the temporary table must be refreshed each time I perform the request.

My question is :

What solution has le lower cost in terms of performance : droping, recreating the table and inserting the new data OR deleting all the records and inserting the new ones?

The table contains less than 500 records.

Temporary Table Inserts?
I was wondering, we all know that temporary tables are system bottleneck, I was wondering if the slowness of inserts for temporary table is related to the number of fields that the temporary table have? What I mean is, would a temporary table with 2 fields run INSERT statements faster than a temporary table with 5 fields?

Nested Query On A Temporary Table
Yeterday I started playing with temporary tables but ran into a problem. Let me describe the situation:

As a programmer of a family tree program I want to know if there are any isolated families in a family tree. The program has a table called families and in this table looks as follows:

Error Inserting Into Temporary Table
I create a temporary table by using following statement:

CREATE TEMPORARY TABLE ttable1(
id tinyint( 4 ) ,
q decimal( 5, 0 )
) TYPE = HEAP

tryng insert a record by statement:
INSERT INTO ttable1 VALUES ('1','1') return the following:
#1146 - Table 'rail.ttable1' doesn't exist

How can I insert in my temp table?

Creating A Temporary Table For Searches
I have a search setup on an intranet site for my company that works pretty good. I do wish it would work a little better, but I'll have to settle for what I have. Let me explain what I'm doing. When a search is made, I run the word through several tables in my database and use FULL TEXT matching on certain fields in those tables to produce results.

I have it set to BOOLEAN MODE so "prod" returns results with "product". As I search through each table, I insert each result into a table I create based on a user's session id. Once I check all tables, I then then run one last query to display the results. Then I drop the table created at the beginning of this process.

The problem is, sometimes the table doesn't get dropped. I don't know why or how, but I end up with a few empty tables in my database at the end of the month. Any ideas as to what could be causing this?

Also, my other issue with this process is I'm using a 'relevance' field to get a "score" of each result, however it seems with BOOLEAN, they all return with a score of "2" or "1", which results in an irrelevant sort order. When I was using standard FULL TEXT search without BOOLEAN, it would return some percentage (like .22340580212). Problem with that method though was it wouldn't return "product" when searched for "prod". So my questions are, i guess:

1. Is there a better way to do this?
2. Is it possible to have the best of both worlds with BOOLEAN and standard FULL TEXT searches?

And the reason i'm not using "LIKE" anymore was 1. I hear this way is much more efficient and 2. there isn't the relevance (or score) feature with LIKE.

Merging Data To Form A Temporary Table
Article (id, title)
ArticlePermissionGroup(articleId, permissionGroupId, allowRead)
PermissionGroup (id, name)

Sample data:
Article:
1, 'article 1'
2, 'article 2'
3, 'article 3'

ArticlePermissionGroup:
0, 1, 1
0, 2, 1
0, 3, 0
1, 1, 1
1, 2, 0
2, 1, 1
3, 2, 0

PermissionGroup:
1, 'Admin'
2, 'User'
3, 'Guest'
4, 'Robot'

The ArticlePermissionGroup table contains two types of permission: the 'defaults' with an articleId of 0 and 'specific' permissions which can be used to override these defaults. So for example the actual permissions for article 1 are:

(permissionGroupId, allowRead)
1, 1
2, 0
3, 0

As you can see the first two rows are specific permissions as rows with articleId = 1 and permissionGroupId = 1 or 2 exist in the ArticlePermissionGroup. However the third row is taken from the default permissions, as no row exists with articleId = 1 and permissionGroupId = 3 in the ArticlePermissionGroup. As there are no specific or default permissions for permission group 4 then no rows exist for this group.

My problem is how do I generate a temporary table (assuming this would be the best approach) that, for each article, contains the combined 'default' and 'specific' permissions - it'd contain the articleId, permissionGroupId and allowRead columns. For the sample data above it'd look like this:

(articleId, permissionGroupId, allowRead)
1, 1, 1
1, 2, 0
1, 3, 0 *
2, 1, 1
2, 2, 1 *
2, 3, 0 *
3, 1, 1 *
3, 2, 0
3, 3, 0 *

The rows marked with * are created from the defaults. Again, because no default or specific permissions exist for permission group 4, there are no rows for this group in the table.

I hope I've explained this well enough - is it possible? Or is this a flawed (or just plain stoopid) idea?

Compare Temporary Table And View In Mysql
may i know that what is the dirrerences between temporary table and view (mysql), which method is more suitable in retrieve tons of data.

Create Temporary Table With Read Permissions Only
In one database I made a query like this

create temporary table tempT type=heap select * from orig_table1;
insert into tempT select * from table2;

SELECT column1, column2, column3, sum(column4) as sumOfColumn4, etc,
WHERE date = 20070306 and name = "jan" GROUP BY Column4 order by name desc;
drop table tempT;

But on another server I only have read permissions. Is there a trick to do such a thing when you only have read permissions. Can I add the output in a variable and then merge the second select in the variable and if necessary empty the variable?

Temporary Table Accessable Only In Instance Of Procedure
If I have a procedure that will be run simultaneously by several people
which requires the use of a temporary table is there a way for the table
to be accessible only in the instance in which the procedure is being
run so that multiple tables can have the same name but not have
collisions?

I would normally think to name the table with a random
string but apparently SQL rules do not allow dynamically generated table
names. The other thing I would try is to have a permanent memory table
with the structure I need, with an additional column that would be
populated with a random number that indicates which batch is being
processed, with the contents being deleted right before the procedure
ends.

I don't know what kind of impact that would have on the server,
and am hesitant to try as my test environment has nowhere near the
capacity of the production environment, in just about every way possible.

Update Column In Table A With The Count Of Another Table
Having my SQL-background in Oracle I'm looking for the MySQL equivalent for:

update tableA
set column1=(select count(*) from tableB where tableA.key= tableB.key)

cannot find anything similar in the manual, but probably overlooking
something.

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

Update Table A For Every Instance In Table B
I have learned how to select records from two tables but now, I need to update every record in table A based on keys found in table B.

I have a KEY which I can match to records in table B and table B has a field which I can match to records in table A.  I need to update table A and possibly table B.

How do I go about this?

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?

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
...

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.

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.

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.

Does anybody know how to access to table sequentially?

Update From One Table To Another ????
I have two tables with linked fields, a one to many relationship.  It is a item sold table to work order table where there are many items sold linked to a single workorder.  I want to add up all the item taxes for the particluar workorder and instert it into the appropriate workorder.  I have tried something like this:

update set workorder.tax (sum)woitem.tax where workorder.id=woitem.linkid

Can someone show me where I am going wrong? 

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?

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!

Update Table
Im trying to update a table, but Im getting the following error...
Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5


Here's my code...

<cfquery>
UPDATE printers SET name= <!---this is line 5 that the error is referring to--->
<cfif IsDefined("FORM.name") AND #FORM.name# NEQ "">
'#FORM.name#'
<cfelse>
NULL
</cfif>
WHERE printerid=#FORM.printerid#
</cfquery>

Update Table
What is the right syntax of UPDATE command, I want to use multiple (more than 5) WHERE clauses and update more than 2 fields.
UPDATE table SET UPDATE1 =’xyz’ UPDATE2 = ‘abc’ WHERE 1=‘zxc’ 2=’wer’ …………?

Update Table
I want to update a number in a column adding a 1 to the current number, however I don't want to select the table first.

Update Table
everytime it tried to update row in any table, it takes very longtime, it locks the table, then i run out of connections and mysql crashes.

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?

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

UPDATE Table
Code:

UPDATE table SET field='select concat(field1,field2) from table'

This gives me a zero in my field
I can select concat separately without any problem

Using Import To Update Table
I'm working on a business directory site that I created using phpmydirectory. All of my data was imported into mysql from the admin area of my site.

My category table has ID, Title, Description, and Keywords fields. At the time that I imported my business listings, I left the Description and Keywords fields blank. I am now wanting to go in and add descriptions and keywords to each category. I would like to setup a simple spreadsheet and fill in the description and keywords for each category, and then use Import in PhpMyAdmin. Is this possible? If so, how would I set it up? Am I making sense? I really have no idea on how to use PhpMyAdmin. I can browse around and export when I need to, but I'm scared I'll screw something up if I try to update a table.



Update A Table Being Selected?
Is there a relatively easy way to fix this bad decision I made long ago? I created a table thusly:

CREATE TABLE `blah` (
`mod_date` date NOT NULL default &#55612;&#57200;-00-00',
`mod_time` time NOT NULL default &#3900;:00:00',
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I added a new field to the table that looks like:

`modified` datetime NOT NULL default &#55612;&#57200;-00-00 00:00:00'
I thought I could update it with:

UPDATE blah
SET modified=(SELECT CONCAT(mod_date, ' ', mod_time) FROM contacts);
But a search in this forum showed that one can't UPDATE a table that is being SELECTed from. There was mention of a temp table (and perhaps JOIN(?)), but further searching has left me wanting.

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.

Update Based On Other Table
I know this is how this query would be written in SQL but I think something isn't working correctly since this is mySQL.

SQL query:
UPDATE watches SET watches.totalhits = ( SELECT COUNT( id ) AS totalhits
FROM watchtracker
WHERE watches.id = watchtracker.watchid )

MySQL said:
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT COUNT(id) as totalhits
FROM watchtracker
WHERE watches

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

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.

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:


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