Update One Field In All Rows
I have a mysql database which contains 24,000 rows. I added a field called "RECALL", which contain null values. What I'm trying to do is fill that field in all 24,000 rows with the value "N".
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
One Field With Multiple Attached Rows, Only Show The Field Once?
I have a table called "Customers", with a field called "Customer name" and a "Customer ID". I have another table called "Projects", with a field called "Project name" and a field called "Customer ID" which references to "Customers" What i am trying to do is: Select a customer. Select the projects that are related to the customer by comparing the Customer ID field. Code:
Copy Field Over, Then Update The Original Field
I want to change a price of a product, but back up the old price. I was trying to do this through two queries, an INSERT and an UPDATE, but it's not working. INSERT the row that will store the backup: INSERT INTO s01_MUS_SalesXProducts ( s01_MUS_SalesXProducts.sale_id , s01_MUS_SalesXProducts.prod_id ) VALUES ( ".(int)$sale_id." , ".(int)$prod_id." ) Then I would copy the prices over and update the original with one UPDATE query: UPDATE s01_Products LEFT JOIN s01_MUS_SalesXProducts ON s01_Products.id = s01_MUS_SalesXProducts.prod_id SET s01_MUS_SalesXProducts.old_price = s01_Products.price , s01_Products.price = ".(float)$sale_price." WHERE s01_Products.id = ".(int)$prod_id." However it is copying the new price to the backup field. Is there a way to do this in two queries? I know if I select the product price before inserting I can do it in 3. Truely I would like to do this in 1, but I don't believe this is possible due to the nature of the queries.
Multiple Update Of 21 Rows
I have a database table which holds price ranges for various classes of hire car and various hire periods. There are 7 different hire classes and 3 different hire periods. 21 records in total. Heres an example of what the table contains: ID......HIRE PERIOD.....HIRE GROUP....PRICE 1..........14.....................a...............25.00 2..........28.....................c...............15.00 The rows are shown in an editable form, which is basically a grid of text fields. I need to figure out the most efficient way of updating all the records when the grid is edited. Do I need to perform 21 individual updates? as I'm worried that this will be too cumbersome when there are multiple users. I thought of one way which involves having a hidden field for each row, called 1,2,3 etc, each with a value of eg. 14,a,25.00 as a comma seperated list. Then I split the post values into arrays and perform various updates. Seems a bit clunky though,
Update Multiple Rows
I have about 20 rows that need to updated together and would rather not have 20 seperate update lines but am not sure what else to do. At the moment it looks something like this: UPDATE movies SET mon='10pm', tues='10pm', wed='11pm' WHERE movie_id='19'... UPDATE movies SET mon='9pm', tues='11pm', wed='4pm' WHERE movie_id='37'... UPDATE movies SET mon='8am', tues='1pm', wed='5pm' WHERE movie_id='19'... There is no logical order to the movie_id's they are selected from the movies table using specific criteria.
Update Yields Zero Rows
I have a PHP query that is suppsed to update a table. When I run it mysql_affected_rows returns a zero. Unfortunately there are no errors I can find to see why. If the query "update" fails like this how do I find out the reason?
Update Multiple Rows
I have an array that I need to put into an existing db column using a perl foreach loop. I can do this using an INSERT statement but the script will be run every day and the source array will be changing as it is based on directory contents so I need to UPDATE vs. INSERT With the INSERT statment the script places each array element on a new row of the db as it should but when I try to use an UPDATE statement, I get a single array element written over and over on each row of the db. Code:
Update All Rows Conditionally
Having a bit of trouble getting this syntax right. It needs to go through each and every row, read a field and if that field = a certain text, update another field in that same row. if(locate('text to locate' , `dbName`.`tblName`.`fld1`) , update `dbName`.`tblName` set `dbName`.`tblName`.`fld2` = 'new text') .
Rows Changed In Update SQL
Is there a way to find out how many rows got updated when i execute a update stmt. I would like to get the updated rows count in SQL. Let me know and Thanks in advance. update stmt where clause; now how can i get the count of rows that got updated.
Update All Rows In A Column
I'm a complete newbie but I'm trying to do something that I would think would be easy. In my table I have a column LICLEVEL with values of Club, Expert and Elite. I need to tack on "USA Cycling - " in front of that value, so that if the current data is "Elite" after the update it will say "USA Cycling - Elite". With 800 records to update, I'm hoping there's a fairly easy way to achieve this with SQL (or PHP).
MySQL Update Speed With 10K+ Of Rows
I Have table called `users` which have 10K+ rows. Each user have a fields called `gold` and `level`. Now each user should get "pow(1.25, level)*100" gold per/hour and it should divide so that users will get 1 gold per time unit. example: user level is 7 and he should get 1.25^7 * 100 gold = 476 gold per hour (1 gold every 7.5 seconds). Now I have a problem. I can't update all users at once every second because it would create too much load for server (mysql load was 100% if I did it). Even if I would do this update in every 7 seconds, it will be too much load for the server. maybe we can determine user gold amount so: user gold = user gold + (seconds_after_last_update/3600); and do update every prime hour? but what happens the when user wants to spend this gold? My mysql-updateing daemon is running in infinite loop doing 1 action every second.
SSH: Select Database And Update Rows
I'm trying to update a few rows in my database via SSH. I have multiple databases on my server and I need to know what I'm doing wrong. I login via SSH and enter $: mysql -u root -p I want to select the database and then run my update command, but when I type. > select [db_name] It just jumps to a new line without any prompt. Can anyone tell me really quick when they do to select a database?
How To Update Multiple Rows With One Query?
I am using PHP/MySQL and need to update 7 rows with one query. Can someone tell me how to do the following so it will update the row for each day of the week? (This obviously doesn't work) $sql = "UPDATE business_hours SET hours='$sunday' WHERE id='$id' AND day='sunday' AND SET hours='$monday' WHERE id='$id' AND day='monday'";
Update Script, But Check If The Value Is The Same On Other Rows
I have a nice user script. In a particular section there is the ability to edit the users on the databse. What I am concerned about is that people may edit the username or email and find its the same username or email that another user has, this can screw up the login system especially two usernames being the same. So is it possible to make it so that if the email/username is the same in another row to give an error, Please note that the input fields for their email and username are already filled in so if they dont come to edit it them they will still output there original username/address.
MySql UPDATE With Duplicate Rows
I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround I've got stuck trying to write a DELETE statement. Here's the table I'm working on: Code:
Update Multiple Rows Within One Table
I have a Dynamically created formfield. Tgis field shows the attached devices off a selected device (for instance you have a pc and in the formfields it shows two attached monitors). The monitors however are in the same database table. (with an other device_id ofcourse). The page with the pc info is shown by using the device_id in the URL. What I want to do is update some fields in this table for the pc but also for the attached devices.... When I do it like this: UPDATE dev SET .... etc. WHERE device_id IN ('#FORM.koppel_2#') It selects both device id's like this: WHERE dev_volgnr IN ('602,603') This doesn't work! However in this example the table should be updated for the devices with device_id 602 and 603. Is this possible? How would I do that?
Import A Csv To Update Only Certain Rows Of Data?
I have an existing mysql table and a csv. I want to import the csv into the table, but it is at a different sort order. There are too many records to sort my csv by hand to match. There is a common 'cd_code' field that both have. Is it possible to import a csv to the table so that each row of the csv is inserted in the correct row of the table, based on the common 'cd_code' field? For example, if I sorted by cd_code asc, it would match the csv, but how to I import the csv into a particular sort?
Can't Update Multiple Rows Via PHP, But Works In PhpMyAdmin
My php script will update 1 row fine, but fails on 2. However, the exact same query works when pasted into phpMyAdmin. THIS QUERY WORKS BOTH IN MY PHP AND PHPMYADMIN: $sql = "update table set color='red' where id='1';"; $sql_do = mysql_query($sql); THIS QUERY WORKS ONLY IN PHPMYADMIN: $sql = "update table set color='red' where id='1'; update table set color='green' where id='2';"; $sql_do = mysql_query($sql); I know the second query is correct, because when I copy it from my php code and paste it into phpMyAdmin, it works. But only the first query, with 1 row update, works from my php code.
The Most Efficient Manner To Update Multiple Rows
I have a table that holds information about people The table is quite large (300,000 rows) I need to write code that update many of the rows in the table Here is what I need to do Two of the fields that I store about each person are: location and country The location is some free text which the user can type in, while the country is the ISO country code, like "US", "ES" and so on I need go over all the records in the database, and for those that have a non-empty location field, to extract the value and to try to guess what country the user is from and to update the Country field accordingly My problem is that I might find that most of the records need updating, and this might lead to 100,00+ update statements I cannot use LOAD DATA as this is product database Is there a way to update multiple rows (each with a different value and condition in a single query?
How To Update/Delete Bunch Of Rows Quickly?
I have a textarea that allow user to edit a bunch of rows of data quickly. It either add/delete/update rows. How do I do it quickly? The db table has rows of names. e.g. the db table has: car |Susan dog |John monkey |Chris John enters: plane boat house After processing, the db table should say car |Susan plane |John boat |John house |John monkey |Chris How do I update the db table quickly? If I use update query, it will update John's rows but there is no rows to update? There are only rows to add and delete at this time. I don't want to delete all records of John every time John enters the data, because a user can potentially have a lot of rows in the table.
Alter One Field In A Row (300 Rows)
example changing id='1' -> id=' 5000' this must be done with over 300 ids Is there a script ot there that can do this? instead of me doing it manually.
Concat A Field In Up To 4 Rows?
A customer can have between 1 and 4 rows, is it possible to make a query that will merge field "A" of all rows and then discard all other rows leaving only 1 row left with the merged data in field "A".
Search Through Rows Until You Hit Field With Right Value
Basically, I'm trying to figure out how i can scroll through the rows in a mysql table until I hit a row which has a field containing a certain string. This is a ruff image of how my database looks (ignore the dots...it wouldn't let me leave white space): id | username | some_field | | some_other_field | 1..|...bill........|...............| |........................| 2..|...fred......|...a value..| |........a value.......| 3..|...ted.......|...............| |........................| 4..|...jeff.......|...............| |........a value......| 5..|...craig.....|...............| |........................| So, basically, i need to be able to start the query a Fred's 'some_field' then I need it to search on until it finds the next field with 'a value' in...in this case it would be Fred's 'some_other_field', but it could also be any other field in the table.
Count Same Field In Rows
i need to calculate the number of the same IP address that appear in the database, how can i do that? example of the database: IP Address Date and Time 127.0.0.1 5/23/2007 127.0.0.1 5/24/2007 192.168.1.2 5/25/2007 192.168.1.5 5/26/2007 127.0.0.1 5/27/2007
Update A Field Only On A Bit
I have a table "state" and I use each bit to store a flag 'YES' or 'NO'. I'd like to update this field but bit per bit.
Can't Update A Field From VB
I've just setup MySQL on a Linux machine and I'm using Visual Basic in Windows to connect to it (using MySQL ODBC 3.51 driver). Everything works fine for browsing the database (used for stock control), but some parts of the VB program refuse to update the database. It was using an Access database (which worked ok) and I'm using the same SQL statement and table structure. Code:
Update Field
Need your help as I have difficulty in updating field in mysql. My problem like this. I want to update data of customers where their expiredate is on 20071231. Then I use below command to retrieve the total customer where their expiredate 20071231: select username from custdb where expiredate='20071231'; The result is it retrieved about 750 customer's username. The problem is, how can I update this 750 customers expiredate without update one by one or using IN?
Update One Field
I'd like to update one field in a table with a substring of another field in the same table. Can anyone show me an example of how to do this?
Update Field
I am a first timer on this forum so apologies if I sound a bit dumb. I have a table called sortcodes where there is a sortcode number which I need to increment by one for each record. I have the "start number" stored in another table. I am using a stored procedure as I thought I would need to do some sort of loop. But I can't seem to achieve the required result. I thought I would be able to do it with an UPDATE table command within a loop but of course the UPDATE command just goes and updates all the matching entries in my sortcodes table without incrementing my counter.
Update A Field
i am doing a forth year project in college and i need to update column week from 1 to 2 when a certain time occurs. is this possible if so what or how do i go about doing it?
UPDATE Field
I want to number records consecutively with an UPDATE command. Can this be done my phpMyAdmin? I tried SET @a:=1; UPDATE table SET field=(@a:=@a+1) where id (condition); (usage is to 'blank out' sensitive information by storing e.g. 'sensitive1', 'sensitive2', 'sensitive3',... and so on in the field.) (yes I prefer it consecutively, the alternatives 'random' and 'id' are in my line of sight).
Update A Field
on my site i have fields in the members database for downloads and submissions. i recently cleared and restored the files but these statistics have been lost and i'd like to figure out the mysql code to restore them. i have a table of "files", with the members id as, m_id and in the "members" table with the field "downloads" and id stored as "id" i realise this is fairly simple but i just cant get my head around the sql syntax yet
SELECTing Rows Where 1 Field Doesn't Repeat
Let's say I have a table something like this: id a b c 1 1 2 3 2 1 3 4 3 2 1 1 4 2 8 4 5 3 1 4 6 3 8 1 And then I want to select the rows, where "a" field doesn't repeat, so the 1st, 3rd and 5th. How do I do that?
Not Selecting Rows Where A Specified Field Is Empty
What I am trying to do in a query, is only select rows where a certain field is not empty. For example, I have a visitor logs table, with the following fields: id | date | pageVisited | referrer Now, I only want to select the rows where there is a referrer. Something like:
Concatenating Multiple Rows To One Field?
I got a slight problem with a web application, its supposed to several entries for a certain ID, and display them as one string. Example: ID | Name ------------- 1 | Jack 1 | Peter 2 | John 2 | Mark 2 | Ellis Expected Result for ID 1 should be "Jack, Peter" for example, or "John, Mark, Ellis" for 2. Least problem would be clipping off a trainling or leading ",", but the main problem is a SELECT statement to get them all in one go. Else I'd have to select every Name per ID, and concatenate them in PHP or elsewhere. Given its around 100 IDs, I'd have to do like 100 querys to get the names, *in addition* to the Querys I need before and after. I want to avoid that, but I couldnt find a simple solution that works in MySQL 4.1 and above, aswell as it mustn't involve Stored Functions or something, because I got no access to the mysqld itself, to add the funcs as modules. Code:
Update Field In A Trigger
I'd like to set a field to the same value as primiary key(id) in a trigger, here is what I have come out: CREATE TRIGGER update_seq AFTER INSERT ON `usr` FOR EACH ROW BEGIN SET old.seq=old.id; END ; id is the primary key while seq is a field that I want it to be same as id, but this trigger does not even compile, got this error: Updating of OLD row is not allowed in trigger any idea how to do this?
Update WHERE Field Exists
is there a way , in MySQL to do this: i have a table with rows id,name,passwd,nickname Check if row with `name`='harry' exists if so, UPDATE with new data if not, INSERT a new record now i'm doing this with a php if else construct, but there must be an easier way.
Can't Update A Field From VB Program
I've just setup MySQL on a Linux machine and I'm using Visual Basic in Windows to connect to it (using MySQL ODBC 3.51 driver). Everything works fine for browsing the database (used for stock control), but some parts of the VB program refuse to update the database. It was using an Access database (which worked ok) and I'm using the same SQL statement and table structure. Code:
Update Field Isn't Working?
I've created a MySQL database that has one table, that table has two fields, the table is called system, the fields are called status and message. The database is used to populate a html table on a page, that works fine. What I need to do though is have a form on a separate page (which i'm going to add http authentication to) with a simply form consisting of a text box, three radio buttons, and the usualy submit and reset buttons. I need to be able to update the database using this simple form. However this isn't for adding new records, it is purely for editing the existing record as it's to edit simple warning messages to display to the visitors when there is a problem with one of the systems. The radio buttons determine which light image is displayed (green, orange, red) and the text box for the short message. However no matter what i try it just in't updating the fields in the database, the following is the html and PHP i'm using: Code:
Can I Do An UPDATE On A Timestamp Field
I am creating a time management system whereby the administrator can go in and UPDATE an existing Timestamp field with a new time. I have the administrator input the date and time in a textbox. Any clue how he can update the field with this new data??? The table TimeTable has columns like TimeStamp, DateStamp and UserID besides Autonum. I think it should be something like... UPDATE TimeTable set TimeStamp=06/29/2005 12:45:56 PM where UserID=10 and DateStamp=06/29/2005 This however errors on me--any clues?
Update A Date Using A SUM(field)
I have been asked to come up with a way of updating a date field, so that it subtracts the total number of days. If there was only one record to add to the field then it would be a simple case of DATE_SUB(m1.date_joined, INTERVAL p1.qual_days DAY) but unfortunately, there can be more than one record in the second table, so I need something like DATE_SUB(m1.date_joined, INTERVAL SUM(p1.qualdays) DAY) but it won't work, even after I add in a GROUP BY statement at the end of the query, I get an error using GROUP BY. I have now resorted to creating a temp table to dump all the calculations in there and then doing an update using the values but I'm trying to find out if there is a better way of doing it.
Update Mysqld Db With New Field
I have 2 MySql dbs on 2 different servers. I need 2 copy the data from one field in db1 and add it into a new field ind db2. What is the easiest way to do this? Both tables have the same number of records. In db1, tableoriginal let's say there's an int field named id and a field named copyme (varchar). The second database has a table called tablenew and has a field called first_table_id that mirrors the original table's id field and I just inserted a new field called pastemehere (varchar).
Can't Update A Field From VB Program
I've just setup MySQL on a Linux machine and I'm using Visual Basic in Windows to connect to it (using MySQL ODBC 3.51 driver). Everything works fine for browsing the database (used for stock control), but some parts of the VB program refuse to update the database. It was using an Access database (which worked ok) and I'm using the same SQL statement and table structure. Here's the SQL statement that VB runs: SELECT Stock.GJGStockCode, Stock.PartName, Stock.Discontinued, Stock.UnitsInStock, Stock.UnitsOnOrder, Stock.ReorderLevel, Stock.ReorderQty, StockSuppliers.SupplierID, StockSuppliers.OrderCode, StockSuppliers.PackQty, StockSuppliers.Price, Stock.PartsToOrder FROM Stock, StockSuppliers WHERE Stock.CurrentSupplier = StockSuppliers.Position AND Stock.GJGStockCode = StockSuppliers.GJGStockCode AND ((Stock.UnitsInStock + Stock.UnitsOnOrder <= Stock.ReorderLevel) OR (Stock.PartsToOrder > 0)) ORDER BY StockSuppliers.SupplierID, Stock.GJGStockCode ....which works ok for browsing the database. If I change the Stock.PartsToOrder field in the VB program, when VB trys to update it I get the error message "Insufficient key column information for updating or refreshing". The Stock table has a primary key (GJGStockCode), and the StockSuppliers table has a primary key (UniqueID) which is an auto_increment bigint. Does anybody know what I need to do to allow VB to update the database? Or is this a VB question!?? - Although the same SQL statement works with an Access database.
Can't UPDATE A TEXT Field
I am creating an events calendar and one of the fields is a description field, which is a TEXT field. I am unable to use the UPDATE command to update this TEXT field. I have read that for MS SQL, you need to use UPDATETEXT but alas, I am using MySQL and there is no such command. I have found nothing in the MySQL documentation on how to update this TEXT field. Could someone shed some light on this, or direct me to the article in the documentation on how to update TEXT fields?
Select Rows Where A Field Value Exists In Another Table
I have a table with a column of email addresses I have a second table with a column of email addresses I want to select all the rows in the first table whose email value exists in the second table Can't get a query to do this without an error,
|