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




Update Values In Column


i have a table with about 500 rows, i need to UPDATE the city column in each row.
I want to remove a comma (",") a space (" ") and the 2 letter state abv ("FL") from all values in the column (named 'city').

example: "Miami, FL" should become "Miami"




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Update Values In A Column
I have a price list that needs increasing by 10%. Is there any way to do an update commmand and multiply all values in the column by 1.1 to achieve this? I've tried various commands but to no avail.

Update Part Of Column Into Another Column
I'm looking for a way to update a SQL column with a portion of info from another column in the same table.

example of a sql command
--------------------------
UPDATE table1
SET table1.columnname1 = table1.columnname2
FROM table
WHERE blah blah blah

Here's the thing... I only need a portion of the data found in the source column. I'm not sure how I would do this then.

for example, the database has countries and states combined into one column like this 'US-DC', 'US-CA', US-FL', etc. I want to separate these into two columns, a country column and a state column.... and I dont want to go though all the results and do this line by line. How would I write the SQL command so that it puts just the country in the country column, and puts just the state in the state column, and it omits the dash all together.

any ideas?

Update With Values
I would like to update an existing row from table A with some values from another row in table A.I've tried several things, also something like the combined "insert into/select" however it did not work saying its not valid SQL.
UPDATE A SET value1=b1.value1, value2=b1.value2 SELECT value1, value2 FROM A;
Any idea what could be wrong? Is the idea valid in SQL after all?

Update And Add On Values
I have a table that has acculumative hours for each member. I want the members to be able to type in two times, then the code to get the difference between the times and add it on to what is already in the database under their name.
Is this just an UPDATE query, or is there more specy stuff involved?

Update Values
I made a mistake converting some time data to unix timecodes while adding some data to a database, and now I noticed some of these dates need to have 15 hours added to the timestamp. So I though about doing a
Code:

UPDATE ntk_news SET date=date+54000 WHERE newsid>0 AND newsid<178

after having a look at the MySQL manual for Update . Did not work, unfortunately.
Anybody knows what I am doing wrong? I took 54000 since that is ~15 hours. The WHERE statement works in a SELECT clause, but then copy-n-pasted into this UPDATE clause it all breaks.

How To Get Different Values From The Column
I am reposting my question here as there's no reply from the other post (different subject). In the column, there are mixture of multiple same and different values.

How do I write to obtain all different values with the limited row? For example, select pet from pet_customers where ?????? order by Date Desc limit 25;

Add Values Into A Column
I have a column called year with the format YYYY-MM-DD, but I would like to have year, mount and day in three different columns in my database. How can I do this?

Column Values.
is there a way i can create a column that returns result the biggest value of other columns?

ie.

table foo has following fields, all INT, except name VARCHAR

name
list
A
B
C

so if name=joe has A=5 B=7 C=9 , i want list=9

is it possible in mysql to create such variable columns? or do i need to make a perl script to update the table with the info based on what I have on A, B, and C.

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

Automatic Update Of Values In Another Db
I am trying to integrate a CMS and a fourm.

As a solution, whenever there is a change in the users table of the CMS db I want to have it automatically changed (updated) in the forum db as well.

Can anyone recommend a solution?

Please note that the two user tables differ in structure, just some columns match, like password and such.

A Column Which Has All Number Values
I heard a column which has all number values does'nt need to be indexed.

Is it true or false?

Cant Set Desired Values In Column.. (ex. 1.jpg)
On my personal test server I have a MySQL Datatabase, and one of the fields is a type VarChar(45). For this column I have the default value set as 0.jpg.

Now, on the server provided to me on the internet I cannot select VarChar(45), and all of the ones I have tried only allow me to enter in 0 as thhe default value.

This is a problem as I need to store the filename in this column, ex 1.jpg, 2.jpg,

Replacing All The Values In A Column..how?
What is the SQL statement to replace ALL the values in a column?

database name = testdb
column name = testcol
value to replace = &#396;'

Multiple Values In Same Column
My table has a column (additional_info) with values like this 'IP=1.1.1.1&ID=1234567'

I have a list of about 1000 ID's which I need to get information on. Right now I'm using a statement like this to retrieve the info:

select * from table_A
where additional_info like '%ID=1234567'
or additional_info like '%ID=2512541'
or additional_info like '%ID=2125413'.....

This is taking a long time to complete. Is there an easier/more efficient way to do this?

Add Percentage To Values In Column
I have a price column in my Database and need to add 20% on to
each figure in the price column, is this possibe with mysql?

Sorting Column With Values A-Z Before AA-ZZ
I need to sort based on a column that has values as follows:

row
----
A
B
C
D
AA
BB
CC
DD
etc.....

i need the data to be sorted and displayed as A-Z then AA-BB.

I saw this thread: http://forums.mysql.com/read.php?100,69968,70410#msg-70410

is there something similar, that would allow me to sort this way.

Increasing All Values In A Column
I have a simple table with 2 fields. Weeknumber and homepage.

Weeknumber starts at 1 and goes up to 40, I am using php to redirect to a different homepage every week,

I am inserting from a text file and once in the database i want to increase every weeknumber by four so i get weeknumber 4 to 43 instead of 1 to 40.

Have Multiple Values To The Same Column?
I have a table called items with two columns one called id and the other one called catagory. is it possible to have two catagories to one item?

How To Get A Minimum And All The Values Of A Same Column
there is a table with has due_Date as one of its fileds. i want to get the minimum value of that column along with other values. How i do this..

at the moment i'm trying to this (this is not working when the due_Date is duplicating..caz that group by thing) i like to have it using pure SQL rather using any mySQL specific commands.

SELECT min(a.due_date), b.due_date
FROM INVOICE_UTILITY_PAY_PLAN_PUB a, INVOICE_UTILITY_PAY_PLAN_PUB b
WHERE a.party_type_db = 'CUSTOMER'
GROUP BY b.due_date;

i want some thing like this for my output

MIN(A.DUE_DATE) DUE_DATE
--------------- -----------
1/1/2000 10/6/2004
1/1/2000 10/6/2004
1/1/2000 11/2/2004

Multiple Values For A Column
I have a table with columns as ID, Name , Aliases and work_duty.
Now the aliases could be 1,2,... or null, right now what i have done is joined each aliases by '|' and stored as single column in the database.
I want to ask like if there a way such that I store all the aliases separetly and when I query through web page using name or aliases whole row is displayed.

Adding Column Values
I have a table with a column that holds integers. In the column, there are 30 rows. My question is this: How do I add up all the values? (I am working also with PHP5) So say the name of the coumn is: CARS. There are 30 rows.Some rows have 0s and others have 1s. So if there are say 15 rows with 0 and 15 with 1s. How do I add up all the values and get the final result: 15 for the column?

Update Query Where Values Will Come From Other Table
I'm creating an update query which the value will come from another table.

I have here my current query which unfortunately makes the system hangs. Probably because of the query itself is not properly coded.

update boxes b inner join messages m
on b.ctnnumber = m.ctnno
set b.consigneerecv = m.CName,
b.consigneerecvdate = m.DateRcv,
b.phrecventered = "Y",
b.PhilStatus = "delivered",
b.prevreleasestatus = b.releasestatus,
b.releasestatus = "delivered",
b.PhilStatusDate = m.smsrecvdate,
b.phdelprice = "0.00",
b.phdelamt = "0.00",
b.recvrelation = m.Relation,
b.APRecventered = m.smsRecvDate
where b.consigneerecv = ''
or b.consigneerecv = 'NA'
or b.consigneerecv is null;

I'm thinking revising it so that it will not cause the system to hang but I don't know how. Guys please help me with this one. I also have this another idea which probably will not work. My idea was something like this:

Update table1 set table1.column1 = (select table2.column1 where table2.column1 = table1.column1),
table1.column2 = (select table2.column2 where table2.column1 = table1.column1), .....

How To List Duplicate Values In A Column?
I have a large table which has duplicate values in one of the columns. I can easily see how many duplicates there are by using COUNT and DISTINCT, but I can't see what the duplicates actually are.

I guess there's a simple way to list duplicates, but I can't get my head round it.

Adding Multiple Column Values
I am tring to find out if it is possible to add INT fields from multiple records on a single query ....

Number Of Values In A Column That Occur Only Once
Can anyone give me a hint on how I write a query to find out the number of values in a column that occur only once?

Pulling Multiple Values Into A Column
i have a database of contacts and surveys, my software is similar to surveymonkey.com where i let people create and use surveys. i need to allow users to export the survey data but i'm having a problem building the columns. Code:

Adding Values Of A Single Column
how can i add all the values of one column of the table to get a total?

Replace Values In One Column All Rows
I need to replace all values in one column with the values from another column - example:

I want to replace all the values in the Username Column with all the values in the EmailAddress column - all rows to be effected.

Trying To Select Values From Column And Count Each Different One
say my column values are thus:

1 | 1
1 | 2
1 | 3
1 | 4
2 | 1
2 | 2
2 | 3
3 | 1
3 | 2

my select is like this:

my $sth = $dbh->prepare("SELECT session_id, col2
From $table
");
$sth->execute;

while ( my @fields = $sth->fetchrow_array) {
print qq( $fields[0] );
}

I want to be able to show that there are three individual values (in col1) and that there are 9 values in col 2. I also need to show that (based on the number of values in col2 [relative to col 1]), that the average number is 3

Should I use select using UNIQUE (or some other value), or, should I select as shown but put it in a perl hash - or soemthing else?

How To Give 4 Default Values To A Column
I need to create a table in which a column is to be specified with 4 default values. Is it possible?

Finding Sum Of Column Values In A Single Row
If I have a table that looks like this...

id, value1, value2, value3, total
1,1,1,1,[?]
2,2,5,4,[?]
3,4,1,1,[?]

What query could be used to update the value in the 'total' column as the sum of each row's value for 'value1', 'value2', and 'value3'?

The results I am seeking to replace [?] would be:

3
11
6

Grouping Column By A Range Of Values
I was wondering if it was possible to group a column of data by a range (rather than a single value) in MySQL? For example, say I have the following data:

Age | Charges
0 | $1938
3 | $19383
4 | $923
3 | $67
11 | $229
2 | $298
5 | $74392
8 | $3792
6 | $6514
7 | $341
2 | $7612

I want to present it as:

Age | AVG(Charges)
0-2 | $XXXX
3-5 | $YYYY
6-9 | $ZZZZ
10+ | $AAAA

Is it doable?

Inserting Multiple Values In One Column
I have a web form that has a drop down list where you can select more than one item. I'd like both of these values to be entered into the same column in a table. For example, the table is set out as follows

TAG_TABLE
tag_id
user_id
software_id

all of the above are integers whose value is referenced in another table.

eg the software_id table is as follows

SOFTWARE_TABLE
software_id
software

The dropdown list in the form is populated from the software table. What happens is that when I select an item from the drop down list say Microsoft Visio it enters the corresponding integer in the main table. But if I select Microsoft Visio and Micrsoft Project, I want both of those integers to somehow be added into the user_id column in the TAG_TABLE.

I also have a web based reports form .....

INSERT Values In Three Tables Using ID Column
how to insert values in different tables?

Table t1 got a column named "id" and this value should appear in t2.t1_id

In other words: How to fill all columns in all tables with one INSERT / UPDATE ?

t1

id bigint autoincrement
name varchar()
bla
bla


t1
id ....

UPDATE Multiple Values - Proper Syntax?
I use powerbuilder with mysql database.I want to get server's datetime.

Update Values On Inserting Duplicate Index
I am very new to mysql. I have a question about using the "on duplicate
update" clause with insert command.

my table "data" has two columns, field1 and field2, where field1 is the
index and is "unique".

when I run

insert ignore into `data` ( `field1`,`field2`)
values
(1,2)
(2,6)
(2,9)
(5,1)

I got
1,2
2,6
5,1

because the third value pair, (2,9) was ignored due to duplication in
field1.

here is what I want to do: when inserting new record with duplicate
index, I want the existing record gets updated. in the above case, I
want the output look like the following after the insert command:
1,2
2,9
5,1
after searching mysql online document, I only found the "on duplicate
update" clause can do something similar, however, all the examples only
show setting the duplicate record to somthing unrelated to the new
values.

How To Insert And Update Multiple Values In One Record
How do I insert and update multiple values in one record. e.g.

1. How do I insert "dogs,cats, snakes" in one record
2. If I have "dogs, cats, snakes" in one record and I want to update it and add 'pigs' to make it "dogs, cats, snakes, pigs", how do I do that?

A Query To Select A Column When A Percentage Of Values Non Zero?
I wounder whether some of the experts out there might be able to help
me with a problem I'm having. I do not know whether this is possible or
not...

I have a large table of stock price data which is straight-forward
enought. I can select prices based on a ticker and date ranges.
However, what I'd like to do is to select prices only when, say 75% of
them are non-zero (with the goal of eliminating new/suspended/delisted
stocks).

Of course I could just select where price > 0, but then I might get
only a few rows where this is the case. What I would like to do is
always get the full date range of prices, but only if >75% are there.

Adding Column Values In MySQL Database Using PHP..
Just a quickie. Is there any way of adding up the values of a column in a table and then assigning them to a variable.

my query is this:

$query=mysql_query("SELECT * FROM table WHERE amount='$amount'");

this will select around 3 or 4 rows from the database. what i want to do is have it add these amounts up and then assign the total amount to one variable.

Counting Occurrences Of Values In Table Column.
I have two tables;

Table 1;

Agent_ID UserID First_Name Last_Name

1ShadShad Mortazavi
2Harry Harry Potter
Table 2;

Recording_IDAgent_ID Status GSM_File etc
11 000001.gsm
21 0 00002.gsm
32 100003.gsm
41 200004.gsm
51 100005.gsm
61 200006.gsm
72 100007.gsm

Status 0 = Red, 1 = Yellow and 2 = Green

I would like a query that returns the number of occurrences of Red, Yellow, Green against each agent

so the data returned would look something like this;

NameREDYellow Green
Shad Mortazavi 2 0 2
Harry Potter 0 2 0

I'm using MySQL version 3.23.58

I can do this programmatically in Perl with several query's; but this is CPU intensive. If I could get this in one query I it would save time.

Pivoting A Column W/ Undetermined Number Of Distinct Values
Suppose I have 2 tables and each table has 2 columns (name, category). I want to make a script that takes in one parameter from the user specifying which table they want to use and then give them a table that has as many columns as there are distinct values within the category column and a count of all people belonging to that distinct category. Code:

MySQL Command To List Enum Values Of A Column? - ALL SET
I'm wondering if there is a MySQL command to list all the enum values of a given column. For example, I have a column defined as:

sgroup enum('none', 'aaaaa', 'bbbbb', 'ccccc') not null
What command can I run to get the list of these possible values?

Append String Of Column Values In SELECT Statement
I'm looking for syntax to append string of column values in SELECT statement.

For example, following is a SQL statement to select the property_address1, property_address2 and property_address3. The values should be returned in accordance to their respective columns.

SELECT property.property_address1, property.property_address2, property.property_address3
FROM orems_property property;

is there any syntax that will enable us to append property_address1, property_address2 and property_address3 is a single column? I've no idea of MySQL, but Oracle syntax would look like the following:

SELECT property.property_address1 || property.property_address2 || property.property_address3
FROM orems_property property;

Date/Time As A Default Values For A Table Column
I am new to mySQL, so this question might be simple.I want to add a default value to a column that is the current date/time. I am using the mySQL Administrator and will not allow me to use a function like CURRENT_TIMESTAMP() or NOW() as a default value. I used to do this with other databases (I always add a column to all of my tables called InsertDateTime and UpdateDateTime. It helps to track down data entry problems)

Creating Column Of Unique Values In Order To Have A Primary Key
I have a flat file that has no columns with unique values.In other words, there is no column available that I can define as the PRIMARY KEY, and thus, cannot incorporate the data into a table.

So, my question is this: How do I modify the table so that I can insert a column of unique values for each record? A column of unique values would be something as simple as a letter followed by the row number of the record (e.g, T1, T2983, etc.).

Updating Column With Sumned Values For Each Record In Table
I have most of the query formulated, but am stuck on the portion where I need to specify which records to update. I want to update all the records in the table. How can I specify the request_id to be the same in both the select and update statement?

Here's the query I'm working on:

Code:


update enhancementrequests2 set
hardBenefitEffortSavings = (SELECT hardBenefitEffortSavings + hardBenefitLaborSavings + hardBenefitHardwareSoftwareSavings
+ hardBenefitOtherSavings AS hbTotal
FROM enhancementrequests where request_id = 1), hardBenefitLaborSavings = NULL, hardBenefitHardwareSoftwareSavings = NULL,
hardBenefitOtherSavings = NULL
where request_id = 1



In my example I have specified that request_id = 1, but I want request_id to match each row of the table in turn. I hope that makes sense.

Field Values Shifting During Load Infile W/column List
I'm loading a text file into a MySQL database using the following (specifics obfuscated out of confidentiality purposes)

CODELOAD DATA INFILE 'file.txt'
INTO TABLE test_temp
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
IGNORE 5 LINES
(col3, col5, col8, col10);

Update A Column
I am using PHPmyAdmin to update a database because I cannot connect with the cool tools you guys have here. So in an effort to just get this one simple take done and overwith I need to know what query to run.

I need to change the table jos_dir_listings where the column says premium from 0's to 1's

however, I do not know the proper query to run. when I run it in the Auto editor that phpMyadmin provides I get a Syntax error.


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