dbTalk Databases Forums  

[ask] WHERE Clause with many values?

comp.databases.mysql comp.databases.mysql


Discuss [ask] WHERE Clause with many values? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
zaqi syah
 
Posts: n/a

Default [ask] WHERE Clause with many values? - 07-24-2011 , 01:58 AM






I want to combine the values ​​of the two fields are still in one table, with the command below :

update kabupaten set id_kabupaten = (
select concat(prop_id, id_kabupaten)
)
where prop_id = 11

but the above command if prop_id weakness is that I got there 50.000 values, it's not very efficient because I have to type them one by one. Please help so that commanded more efficient. Thanks b4

Reply With Quote
  #2  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: [ask] WHERE Clause with many values? - 07-24-2011 , 12:55 PM






On Sat, 23 Jul 2011 23:58:32 -0700 (PDT), zaqi syah wrote:

Quote:
I want to combine the values ??????of the two fields are still in one
table, with the command below :

update kabupaten set id_kabupaten = ( select concat(prop_id,
id_kabupaten) ) where prop_id = 11

but the above command if prop_id weakness is that I got there 50.000
values, it's not very efficient because I have to type them one by
one. Please help so that commanded more efficient. Thanks b4
No need for the WHERE clause, if you want all the rows so updated.
Since this query is potentially destructive could be repeated and cause
problems, you may wish to add another column to the table, concat() the
values into that, and (when you are satisfied with the results), replace
id_kabupaten via a single

UPDATE kabupaten SET id_kabupaten = your_new_column

and then drop your_new_column from the table.

--
It is odd, but on the infrequent occasions when I have been called upon
in a formal place to play the bongo drums, the introducer never seems
to find it necessary to mention that I also do theoretical physics.
--Feynman

Reply With Quote
  #3  
Old   
onedbguru
 
Posts: n/a

Default Re: WHERE Clause with many values? - 07-25-2011 , 04:38 PM



On Jul 24, 1:55*pm, "Peter H. Coffin" <hell... (AT) ninehells (DOT) com> wrote:
Quote:
On Sat, 23 Jul 2011 23:58:32 -0700 (PDT), zaqi syah wrote:
I want to combine the values ??????of the two fields are still in one
table, with the command below :

update kabupaten set id_kabupaten = ( select concat(prop_id,
id_kabupaten) ) where prop_id = 11

but the above command if prop_id weakness is that I got there 50.000
values, it's not very efficient because I have to type them one by
one. Please help so that commanded more efficient. Thanks b4

No need for the WHERE clause, if you want all the rows so updated.
Since this query is potentially destructive could be repeated and cause
problems, you may wish to add another column to the table, concat() the
values into that, and (when you are satisfied with the results), replace
id_kabupaten via a single

UPDATE kabupaten SET id_kabupaten = your_new_column

and then drop your_new_column from the table.

--
It is odd, but on the infrequent occasions when I have been called upon
in a formal place to play the bongo drums, the introducer never seems
to find it necessary to mention that I also do theoretical physics.
* * * * * * * * --Feynman
except that he apparently only wants to perform this on something less
than the entire table.

update kabupaten set id_kabupaten = concat(prop_id, id_kabupaten)
where prop_id = 11;


mysql> create table abc (a integer, b integer);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into abc values (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select concat(a,b) from abc;
+-------------+
Quote:
concat(a,b) |
+-------------+
11 |
22 |
33 |
+-------------+
3 rows in set (0.03 sec)

mysql> update abc set a=concat(a,b) where b=2;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from abc;
+------+------+
Quote:
a | b |
+------+------+
1 | 1 |
22 | 2 |
3 | 3 |
+------+------+
3 rows in set (0.00 sec)

mysql>

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.