Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to query its

Author  Topic 

gacoksa
Starting Member

1 Post

Posted - 2012-08-17 : 17:06:57
hi all, help me please.

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 insert a string $string = "I LOVE YOU" to b_table(phone,message).

condition row of b_table After Query/ Insert is:
----+----------------+----------------------+
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-17 : 17:12:22
below is the way you do it in t-sql


INSERT INTO b_table(id,phone,message)
SELECT id,phone,'I LOVE YOU'
FROM a_table


but i see that you're using MySQL so i cant guarantee it works in MySQL

also learn that this is MS SQL Server forum and we have mostly t-sql experts here

so you may be better off posting it in some MySQL forums like www.dbforums.com if above solution doesnt work

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -