Current location: Hot Scripts Forums » Programming Languages » PHP » Insert...select


Insert...select

Reply
  #1 (permalink)  
Old 07-30-03, 03:42 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Insert...select

Should this work in MySQL?? All the ID-tables are primary keys in the table they belong to, but i have not made any Foreign keys in the Title table. Do i need that?

insert into title(GenreID,MediaID,ActorID,Movietitle)
values
(
(select genreID from Genre where Genre.GenreName = 'Action'),
(select MediaID from Media where Media.MediaType = 'DVD'),
(select ActorID from Actor where Actor.Name = 'Robert DeNiro'),
'Heat'
);
Reply With Quote
  #2 (permalink)  
Old 07-30-03, 12:37 PM
tai fu's Avatar
tai fu tai fu is offline
me
 
Join Date: Jul 2003
Location: Greece
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
What the???

Is that a language or just mysql commands??

Why not just try simple queries??

INSERT INTO title blablabla... VAlUES blablabal??
__________________
let my source be on your side...
<a href="http://www.programersguild.com">Programer's Guild</a><a href="http://gcf.linuxserver.at">Gnome Code factory
</a>
Reply With Quote
  #3 (permalink)  
Old 07-31-03, 04:16 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
I want to insert values from the other tables, so inserting direct values is no good. How would I get this solved? Index? how does that work? do i need it?
Reply With Quote
  #4 (permalink)  
Old 08-04-03, 03:37 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
first you need mysql version 4.1 or greater for sub selects.

maybe you can dump a little bit of your database strture and a line of data on here so we can what you are trying to do, in most cases you dont need to use subselects.
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
  #5 (permalink)  
Old 08-04-03, 06:53 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
what I want to do is quite simple. I want to extract a value from, for instance, genre.genreID and insert it into title.genreID.

Maybe I can extract the value into a ASP variable, and then insert that? Am i getting closer?

Thanks for all the help...
Reply With Quote
  #6 (permalink)  
Old 08-21-03, 05:07 PM
tai fu's Avatar
tai fu tai fu is offline
me
 
Join Date: Jul 2003
Location: Greece
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
I dont know ASP , only PHP, but you have to notice here that you are changing Database
I quess the querries would be
SELECT value FROM genreID
and then change db and execute the query
INSERT INTO genreID VALUES ("value")

Those are your queries
__________________
let my source be on your side...
<a href="http://www.programersguild.com">Programer's Guild</a><a href="http://gcf.linuxserver.at">Gnome Code factory
</a>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Skin awais PHP 5 01-02-04 02:37 PM
PHP Can't select database EST PHP 4 08-19-03 10:14 AM
insert statement sasi ASP 0 08-11-03 09:38 PM
select & delete mysql queries superman PHP 2 07-20-03 03:08 AM
Avatar? I can't insert one... PeTAR Hot Scripts Forum Questions, Suggestions and Feedback 6 06-14-03 02:48 AM


All times are GMT -5. The time now is 04:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.