database - MYSQL Move data from one table column to another table column if condition is matched -


i'm not mysql guy more php guy :)

i have issue copying values 1 table column table column.

the trick data should copied if condition matched. want transfer categoryid 1 table if postids same.

i have 2 tables news , news_in_category

in news table have following columns (id, title, categoryid)

in news_in_category have following columns (newsid, newscategoryid)

so want move newscategoryid categoryid if newsid same id.

for example if news table id=99 should in news_in_category table find newsid value 99 , copy newscategoryid value news table categoryid id 99

hope makes sense :)

thank you!

try:

update news n join news_in_category nic on n.id = nic.newsid set n.categoryid = nic.newscategoryid 

it looks might have redundant functional dependency: newsid -> categoryid. if so, drop news_in_category table without loss of information, after running query above.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

r - Update two sets of radiobuttons reactively - shiny -