If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to insert a row of data using a condition

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-04-07, 22:24
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
How to insert a row of data using a condition

Hello everyone.

I have sort of an issue that I have stumbled on and don't know how to resolve it. Maybe someone can point me in the right direction here.

I have 3 tables like so:

Code:
dspatch
dispatch_Id

narrative
narrative_id
dispatch_id

narrative_Photo
photo_id
narrative_id
path
size

Here is some sample data from the narrative_Photo tale I am having a problem with:

Code:
photo_id     narrative_id     path          size
1            1                /docs/1.jpg     1kb
Here is the sql I am using so far:
Code:
SELECT
`narrative_Photo`.`narrative_Photo_Id`,
`narrative_Photo`.`path`
FROM
`narrative_Photo`
Inner Join `narrative` ON `narrative`.`narrative_Id` = `narrative_Photo`.`narrative_Id`
Inner Join `dispatch` ON `dispatch`.`dispatch_Id` = `narrative`.`dispatch_Id`
WHERE
`dispatch`.`incident_Number_Id` =  '1'
I need a second condition for the "dispatch_Id". My php code needs to first match the row where the dispatch_Id = something then insert the rest of the data.

I could get around this whole issue if I just put the PK from the incident table as the FK in the narrative_Photo table, effectively bypassing the incident table but that is not correct. I hope I am making myself clear.

Can someone please give me a hand?

Thanks
Reply With Quote
  #2 (permalink)  
Old 07-05-07, 03:37
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I'm somewhat confused.
First off, what is the DDL for your tables? I can guess integers and varchars but it may not be the case.
Secondly, i'm not sure i follow the question.

1) Are you trying to insert data?
2) If yes, what data are you inserting?
3) Are you attempting to insert "cross-table" i.e. into more than 1 table at a time.

From what I can see from your post you are doing a select statement, which doesn't make sense in relevance to the question title. What are you inserting and where?
Reply With Quote
  #3 (permalink)  
Old 07-05-07, 06:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by fjm1967
I could get around this whole issue if I just put the PK from the incident table as the FK in the narrative_Photo table, effectively bypassing the incident table but that is not correct. I hope I am making myself clear.
sorry, you aren't

incident table? what incident table?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 07-05-07, 15:12
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Thank you both for your replies. I am thinking that this is more of a php session question than an sql question.

With the sql, I can generate the insert statement that I need but in php it is different.

I think I really need to understand what is happening first with the php. I'll post back if I still need help..

Thank you!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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