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
Post a Comment