Currently I have data that it must has 1 title and 1 content, and randomly number (or none) link group (linktext and link ) , (as the it is dynamic generated) E.g. LinkText1 , Link1 , LinkText2, Link2....and so on. So, one example data is:
title:"abc"
content:"test"
linktext1:"yahoo"
link1:"http://yahoo.com"
The problem is if I would like to update the data in minimum step. The approach I can think of is:
- update the title and content
- select its id
- Base on the id to select the related linktext, link
- If it exist, update
- If not exist , insert
- If before exist , but now not exist, delete
I would like to do this in more elegant way. Are there any combine SQL or which way can I minimum the query ? Thanks
Updated : Data Structure:
Table: news
id
title
content
Table: news_link
id
title
url
news_id
news and news_link is 1=m relation.
news_id is the foreign key of news , thanks