mysql - How do I insert a reference value stored in a reference table into another table? -


i have 2 tables in mysql db: 1 stores guides scrape other sites , 1 stores names, redundant, avoid storing same things many times.

guides:

  • id(int)
  • name(int)
  • title(varchar)
  • url(varchar)

names:

  • id
  • name

i have scraper extracts data multiple websites , insert parsed data mysql db: title, url. know name too, how can compare name have ones in reference table , insert id guides.name? how can

insert  guides         (name, title, url) select  n.id ,       'thetitleyouhave' ,       'theurlyouhave'    names n   n.name = 'thenameyouhave' 

or:

insert  guides         (name, title, url) values  (         (         select  id            names           name = 'thenameyouhave'         ) ,       'thetitleyouhave' ,       'theurlyouhave'         ) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -