I want to add a blog post to a single SQL statement.
My table will look like this:
Tags + ------- + ----------- + | Tagged | Tag | + ------- + ----------- + | 1 | News | | 2 | Top Story | + ------- + ----------- + Tag 2 post + ---- + -------- + ------- + | ID | Postid | Tagged | + ---- + -------- + ------- + | 0 | 322 | 1 | + ---- + -------- + ------- +
I would like to solve the problem Put a new tag , Retrieve its ID in a SQL statement, and then inset this new ID in the relation table .
INSERT tag 2 post (postid, tagged) value (332, # if IF (tag tag with tag where tag = 'new_tag' select), (from where to tag tag with tag) Select tag = 'new_tag'), # where I want to insert #new_tag and return it 'I have lost it here'))
< Div class = "post-text" itemprop = "text">
You can not do this as a single inclusion because inserts are atoms - that is, unless the statement is complete ID is not set.
Wrap the two details in the transaction and you will get your ID, and atomicity.
Comments
Post a Comment