Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

SELETC...INSERT plus a String

Codes here !

Moderators: macek, egami, gesf

SELETC...INSERT plus a String

Postby gacoksa » Fri Aug 17, 2012 1:24 pm

hi all, help me please.
Code: Select all
CREATE TABLE `a_table` (
  `id` int(11) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `group` varchar(20) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
INSERT INTO `a_table` VALUES (1, '111', 'cd');
INSERT INTO `a_table` VALUES (2, '222', 'cd');
INSERT INTO `a_table` VALUES (3, '333', 'cd');
INSERT INTO `a_table` VALUES (4, '444', 'xy');
INSERT INTO `a_table` VALUES (5, '555', 'xy');
INSERT INTO `a_table` VALUES (6, '666', 'xy');

CREATE TABLE `b_table` (
`id` VARCHAR( 11 ) NOT NULL ,
`phone` VARCHAR( 20 ) NOT NULL ,
`message` VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;


I want to SELECT phone FROM a_table WHERE group =xy. and insert a string = "I LOVE YOU" to b_table(phone,message).

condition row of b_table After Query/ Insert is:
Code: Select all
----+----------------+----------------------+
id  | phone          |  message             |
----+----------------+----------------------+
1   | 444            |  I LOVE YOU          |
----+----------------+----------------------+
2   | 555            |  I LOVE YOU          |
----+----------------+----------------------+
3   | 666            |  I LOVE YOU          |
----+----------------+----------------------+



how to create query for this problem.
Thank you.
gacoksa
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Aug 16, 2012 12:14 pm

Re: SELETC...INSERT plus a String

Postby NigelRen » Fri Aug 17, 2012 11:28 pm

Sounds like you want to use an insert ... select type statement - http://dev.mysql.com/doc/refman/5.1/en/ ... elect.html.

You should be able to work out from their example of
Code: Select all
INSERT INTO tbl_temp2 (fld_id)
  SELECT tbl_temp1.fld_order_id
  FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

what this should be as you already have most of it.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron