0

i had a table categories(cid int primekey,name varchar,description text,parent_id,created date,updated date)
i want a script for insertion like this
insert into categories(...) values(cid value,name value,..desc, parent_Id..);
can i write the statement as
insert into categories(....) values (1,'aaa','some text',select parent_id from categories where parent_id=id,date,date);
just i wana know how can i write a select statement in insert statement
so that i can the column value through select statement.
in above querry i have to pick the parent value from cid.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by saurav.prasad28
0

You can try following, but I am not able to understand what is id in "parent_id=id".

insert into categories(....) values select 1,'aaa','some text', parent_id date,date from categories where parent_id=id;

Are you going to execute above query in php or mysql directly?

0
"Table"	"Create Table"
"categories1"	"CREATE TABLE `categories1` (
  `cid` int(11) NOT NULL,
  `name` varchar(30) default NULL,
  `parentid` int(11) default NULL,
  PRIMARY KEY  (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1"


"cid"	"name"	"parentid"
"1"	"A"	"22"
"2"	"B"	"23"


"Table"	"Create Table"
"categories2"	"CREATE TABLE `categories2` (
  `parentid` int(11) default NULL,
  `cid` int(11) default NULL,
  `Name` varchar(30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1"

"parentid"	"cid"	"Name"
"33"	                 \N	\N
"34"	                 \N	\N
"35"	                 \N	\N



insert into categories2 (cid, name, parentid) 
select '3', 'C', categories1.parentid from categories1 where categories1.cid = 2;


"parentid"	"cid"	"Name"
"33"	                 \N	\N
"34"	                 \N	\N
"35"	                 \N	\N
"23"	                 "3"	"C"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.