February 5th, 2013, 04:48 AM
Join Date: Jul 2005
Time spent in forums: 1 Day 6 h 47 m 25 sec
Reputation Power: 9
Get relationship id and use in same query
I wasn't sure if this was possible. I'm trying to avoid doing 2 querys. I have 3 simple tables
id, tag (string)
In my server side script I currently have the value for tags.tag and comments.id. What I need to do is insert into the tags_comments table the comments.id and corresponding tag.id that matches the tag string.
My question is there a way to retrieve the id value from the tags table and use it in the tags_comments insert based on the unique tag string. All in one query?
In my head the query would be,
Insert into tags_comments (comment_id, tag_id) values '2' , select tags.tag_id where tags_tag = %tagstring%
I hope this makes some sense.