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




UPDATE Multiple Values - Proper Syntax?


I use powerbuilder with mysql database.I want to get server's datetime.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Proper Syntax
I keep getting a syntax error. Can you someone tell me what's wrong here.

CODESELECT employee_time.eid, ids_oa.oa_name, employee_time.req_num, employee_time.num_hrs, ids_worktype.worktype, employee_time.`date`, employee_time.num_of_changes, employee_time.comments
FROM employee_time
WHERE employee_time.`date`>= 'startdate' AND employee_time.`date` <= 'enddate'  AND employee_time.eid = 'analyst'
JOIN ids_oa ON employee_time.oaid=ids_oa.oaid
JOIN ids_worktype ON employee_time.work_type=ids_worktype.wid

Update Syntax For Multiple Columns
I'm looking for a feature I'm accustomed to with other SQL products, whereby multiple columns can be updated with a single SET clause, e.g.:

UPDATE tab1 SET (col1, col2, col3) = (SELECT col4, col5, col6 FROM tab2 WHERE tab2.col1 = tab1.col1);

I don't see this feature documented for MySQL. Is there a way to accomplish it?

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?

Proper Case For Multiple Words
I've got a table that unfortunately has many rows that have varchar fields all in capitals, for example, WASHINGTON rather than Washington.
I've used CONCAT( UCASE(LEFT(address3,1)), LCASE(SUBSTRING(address3,2)) ), but this really only works for single word fields, for example WASHINGTON STATE. Can someone here help me with a function or procedure? Or has someone done it before.
Usually we would do this in the application code however time is of the essence here and our application coding is outsourced (company would charge us a fortune for even a small change).

Help With Update Syntax
This is a fairly common task, but for some reason I'm blanking and haven't had any luck with the manual.

What I want is a query that tries to update a record on a table, or if the record doesn't exist it inserts it.

Is there a single query way to accomplish that?

Update Syntax Help
I am UPDATING a profile table based on $id and $company_id.

$id = 10
$company_id = 500

profile:
p_id, company_id, client_id
10,50,100
20,40,80
30,60,120

My update statement looks like this..

PHP

UPDATE profile SET company_id = '$company_id' WHERE p_id = '$id'";
UPDATE profile SET company_id = ņ“' WHERE p_id = &#3910;'";

But I have another table I need to update called user2company which has records than correspond to the user table. These records in user table doesnt change.

user:
increment_id,profile_id,login_id,password
1,10,joe,pass1
2,10,mary,pass2
3,20,sam,pass3
4,30,bill,pass4

user.profile_id is linked to profile.p_id

user2company:
id, company_id
1,50
2,50
3,40
4,60

user2company.ID is linked to user.increment_id

Now how to I update my user2company.company_id when my profile.company_id changes for only the condition p_id = 10?

Final result:

profile:
id, company_id, client_id
10,500,100
20,40,80
30,60,120

user2company:
id, company_id
1,500
2,500
3,40
4,60
I tried an UPDATE syntax but what happens is that all of my records in user2company.company_id changes to 500

Update Syntax
I have an autoincrement table with about 32 columns. (mysql5) The first column is the auto incrmenting index. I need to retrieve a row from the table, update multiple fields in the row and write the row back to the table with the same index. I have read the manual but (newbie) don't understand how to do this.

UPDATE Syntax
I'm having problem with an UPDATE syntax. I want to update 2 fields from a certain record in a table. The following syntax works:

UPDATE items SET price='30' WHERE num='1'

BUT When I try to update 2 fields using the following syntax I get an error saying that my syntax is wrong.

UPDATE items SET desc='cheese',price='30' WHERE num='1'

What's wrong with it?

UPDATE Syntax
I am running Apache version : Apache/1.3.33 (Win32), PHP version : 5.0.4 and MySQL version : 4.1.10a-nt - extension : mysqli on my home computer.

When I execute the following SQL it works fine.
UPDATE places SET places_count = (SELECT COUNT(*) FROM joins WHERE joins.pid = places.pid)

However, when I try to run it on my hosted site which uses Apache version : Apache/1.3.33 (Unix), PHP version : 4.3.11 and MySQL version : 4.0.25 I get the following error.

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(*) FROM joins WHERE joins.pid = places.pid)' at li

UPDATE Syntax
What if I use UPDATE blablabla WHERE blablabla but there actually isn“t a row in the table that would fit the WHERE statement? Does it just ignore it or does it screw it up?

Also if i use the same syntax and there is a lot of records that fit the WHERE statement, how can I limit it so that it only updates one row.

Update Syntax
well i know the update syntx and i am using this:

Update SilverProducts
set id = 'sl209',
set category = 'Anklets',
set description = 'anklets',
set price = '29.99',
set weight = '12',
set diameter = '25'
where id = 'sl209'

however i get an error saying something wrong near "set category..." line? but i cant figure out what

Update Syntax
I am having some trouble with an update query:

update mytable set field_a='test', field_b='test2' where uid=(select uid from mytable where time='09:00' and field_a is NULL order by uid limit 1)

I get the error Quote: You can't specify target table 'mytable' for update in FROM clause I can understand why I get this error but what can I do to fix this?
Here's what I am trying to do:
I have a table to sign up people and there can be 3 entries per timeslot. In the beginning, the table has entries for each time slot with field_a and field_b set to NULL. When a user signs up for a time, I want to put them into the first available slot for that time.

UPDATE SQL Syntax
I need to do an Update that involves writing to table tblDateLog based on the values in tblConcess as follows
CODEUPDATE tblDateLog, tblConcess
SET tblDateLog.OpenEarly = [EndDate] + [DefOpenEarly],
tblDateLog.DataDueIn = [EndDate] + [DefDataIn],
tblDateLog.FirstRemind = [EndDate] + [DefFirstRemind],
tblDateLog.SecondRemind = [EndDate] + [DefSecondRemind],
tblDateLog.WarningFlag = [EndDate] + [DefWarningFlag]
WHERE tblConcess.ConcesId = tblDateLog.ConcesRef
AND DataDueIn = 0000-00-00

Update Syntax
I am trying to figure out a way to use mysqldump (table is too big for phpmyadmin) or another means to dump a file. Within the file, I don't want the insert syntax. What I would like to find out how to do is basically update each record (except for the field in the table that counts clicks) and then insert the records that are not in the database already.
I need this in a file format because I upload the file to my server after building the 1 million record DB locally.

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.

UPDATE Syntax Check
Can someone check this for syntax errors because I it won't execute without an error:

CODEUPDATE pages SET NAME='index', GROUP='all', HITS='1', HTML='This is just the index page from the MySQL database!  Congrats, so far so good!', HTTPS='0' WHERE NAME = 'index'

Update Syntax For Version 3.23.58
I wanted to do a simple update like this in version 3.23.58 of MySql:

Update CLI, TEMP set CLI.ORN = TEMP.C WHERE CLI.ID = TEMP.CLI_ID;

Turns out you can not.

What is going on here and what are my alternatives?

Update Syntax For Mysql
I would like to request for your expertise. I have here an update statement which updates the table1 columns(not all columns) from the values in table2. Table1 has 20 records and Table2 has only 14 records. Like I said, I want to update the 14 records in table1 from the 14 records in table2.

here is my update statement:

Bulk Update Syntax
I heard many times about bulk update, can anyone show me an example of how to do it?

UPDATE Syntax Creating New Row And Id#
I'm using the UPDATE syntax, based on the MySQL documentation:

UPDATE table SET col1 = value1,
col2 = value2
WHERE id = 1

* the id column is set as an auto-increment index in the MySQL setup.

I want it to update/edit the row where id = 1
BUT instead, it's adding a new row with another id # with the col1 and col2 data (not quite updating the row, eh?).

UPDATE Syntax Error
I've just installed MySQL 5 on my Mac and am trying to update a couple of tables - the syntax I'm using seems to be right, but I constantly get an error.

Here's what I have - feel free to point out my stupidity...

SELECT ibf_members.id,
ibf_pfields_content.member_id,
ibf_members.mgroup,
ibf_pfields_content.field_2
FROM ibf_members INNER JOIN ibf_pfields_content ON ibf_members.id = ibf_pfields_content.member_id

UPDATE ibf_pfields_content
SET field_2='Member'
WHERE ibf_members.mgroup = 3

Correct Syntax For An Update
two databases, one has an out of date email field.
I need the new table to update the email field on the old table.

My query selects the rows with the wrong email address:
select * FROM `oldtable` , `newtable` WHERE oldtable.memberid = newtable.memberid and oldtable.Email != newtable.email

but how do I update it?
update`oldtable`set oldtable.Email = newtable.email where oldtable.memberid = newtable.memberid

My above query fails.

Mysql Update Syntax
I am using mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386)
I have problem with the following syntax:

Update t1, t2
set t1.id = t2.id where t1.name = t2.tname OR t1.code = t2.tcode;

I am trying to update the value of id in t1 using t2 attributes where the conditions fit in.

ON DUPLICATE KEY UPDATE Syntax
I have two tables with identical columns. I want to update records in tbl1 with record information from tbl2.Code:

INSERT INTO tbl1 SELECT * FROM tbl2 ON DUPLICATE KEY UPDATE SET tbl1.col=tbl2.col, tbl1.col2=tbl2.col2

I seem to be missing something here...

Multiple Values
I'm working on an application that allows people to publish training information to a database. They have an option to specify how the course is delivered i.e Classroom, Web Based, etc. This is a checkbox value so a single course can be delivered in multiple ways.
But what's the best way to store this in the database? The immediate solution that comes to mind is to place all the selected deliveries as comma separated values in the same column. In the corresponding Java object the values will be stored in a String array, and since there won't be a huge number of delivery options it won't be difficult to manage.
Is this typical or deemed or a good design though?

Regarding Multiple Values
I am in the process of constructing a database that will store Latitude and Longitude points for a given location or marker. Because I want to cover Lat/Long points for a line or an Area, I will need to store a list of Lat/Long points for a given marker. Likewise I would like to store a list of keywords that are unique to a particular marker.
My initial impression was that I could assign an array to a row element and store a list of points in there, but it is clear that its not possible. What are my alternatives?

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

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

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"

Simple Question About UPDATE Syntax
I have an INSERT query that looks like this :

insert into student(student_id, student_name, school_id)
values(&#55619;&#56447;','CHAN, DAVID',&#395;');
Am I able to create a similar query for UPDATE? Something like

update student set(student_name, school_id) where student_id = 5
values(&#55617;&#56524;','Kelly, Ned');
I wish to achieve a query where the new values are seperate from the query. Seeing as I cant find this anywhere online and I get errors when I test it, I am supposing not. If anyone could tell me for sure, I'd appreciate it!



Dumping File With Using Update Syntax
I am trying to figure out a way to use mysqldump (table is too big for phpmyadmin) or another means to dump a file. Within the file, I don't want the insert syntax. What I would like to find out how to do is basically update each record (except for the field in the table that counts clicks) and then insert the records that are not in the database already.

I need this in a file format because I upload the file to my server after building the 1 million record DB locally.

MySQL Update Syntax Error
I am currently developing a simple content management system for my personal website hosted at waynegrills.co.uk and have stepped into a trench full of water with no rope to help me out, if you get what I mean, this error keeps on popping up what is wrong with the following code?

if(isset($_GET['changeorder']))
{
foreach ($HTTP_POST_VARS as $key=>$value)
{
if (substr($key, 0, 6) == "order|")
{
$orderid = substr($key, 6);
$query = "UPDATE pages SET order = '$value' WHERE id = '$orderid' LIMIT 1";
mysql_query($query)
or die("The coder FUCKED up - SQL Error: ".mysql_error());
}
}
}

Count Multiple Values
I have a very basic question but I havent found answer to it anywhere.

I have a table that has following columns: date, answer1, answer2,
answer3, answer4
and entry: 2007-1-1, 'a', 'b', 'a', 'c'

What I want to do is count number of character "a":s as an answer.
Normally (if using COUNT, MATCH..AGAINST) mysql returns rows it finds.
I want to find out how many times this character "a" appears in a
record.

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?

Recording Multiple Values
I'm trying to save as many integer values as possible for any user into a table.

Ex: Fist the user starts out with no additional values other than their name and password, and the iteam field is blank. And then if the user buys something it should record that into the iteam field, and when the user buys again it'll add on values in the same field.

Multiple Values In One Field
Is it ok to store multiple values in one field? I have a site where users input Category Name and Category Index into a form. I want to be able to store both values in one field;

for example: 0|News or 1|Sports

The reason for this is long so I won't bore you, but I just want to know if I will run into problems doing this?

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?

Storing Multiple Values
I have a table which has a a number of tv stations. There is also a table which is suppose to hold advertisers. An advertiser can subscribe to a specific number of stations. How can I keep track of the variable number of stations that a advertiser can subscribe too? I don't think I can store an array as a field in the advertisers table.

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.

Syntax To Pass Multiple Variables In A Url
What does the url have to look like when passing multiple variables to another page?

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

Blob Update In Perl DBI Gives Syntax Error
I have a Perl app that stores pictures in a blob. Now I want to load a
thumbnail version of the picture into another blob column, but the update
fails with a syntax error. I'm able to insert the new record, with blobs,
into a separate table, but can't update the original record. Is it not
possible to update blobs?

Blob Update In Perl DBI Gives Syntax Error
I have a Perl app that stores pictures in a blob. Now I want to load a
thumbnail version of the picture into another blob column, but the update
fails with a syntax error. I'm able to insert the new record, with blobs,
into a separate table, but can't update the original record. Is it not
possible to update blobs?

Selecting Two Values From Multiple Tables
My apologies for making this post, i'm sure that this question has been answered before, but for the life of me I just don't know what keywords to use.

Two tables, sold_items (buyer_id, seller_id) and users (id, nick).

My objective is to loop through the sold items for a particular buyer_id, and retrieve the buyer and seller username (nick).

The problem is that I don't get how I can select both nicknames when as far as I know, I can only join the buyer_id OR seller_id to the user table.

This is how I would do it normally

PHP

$query = mysql_query("SELECT s.buyer_id, s.seller_id, u.nick FROM sold_items s, users u WHERE s.buyer_id = u.id");

while ($row = mysql_fetch_array($query))
{
  $buyer_nick = $row['nick'];
  $seller_nick = mysql_result(mysql_query("SELECT nick FROM users WHERE id = ".$row['seller_id']),0);
}

As you can see this creates a query inside the loop, but how could I select both nicks in a single query?

Select Multiple Distinct Values
How do I select a distinct value, and the id for that row?


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