I have two mysql tables, table A and Table B. Table B contains publication names and ids. Table A contains reference information and id of the publication from the publication name.
I need to update some values in Table A, I am able to do it for rest of the values using simple update command:
UPDATE reference SET issue ='4',
doi ='',
url ='https://app.dimensions.ai/details/publication/pub.1077608314' ,
issn=''
where id = 9433356;
though I also need to update one of the column, publication. Now I have to value of the publication. I was wondering if I can write this in one single query, where i insert the value in table B or if the value exists in table b, get the id and update the value in table A.
Table A definitions:
CREATE TABLE `reference` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`end_page` int(11) DEFAULT NULL,
`number` int(11) DEFAULT NULL,
`published` datetime DEFAULT NULL,
`reference_id` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`start_page` int(11) DEFAULT NULL,
`volume` int(11) DEFAULT NULL,
`project` int(11) NOT NULL,
`publication_source` int(11) NOT NULL,
`seed` tinyint(1) NOT NULL DEFAULT '0',
`accession_number` varchar(128) COLLATE utf8_bin DEFAULT NULL,
`database_name` varchar(1024) COLLATE utf8_bin DEFAULT NULL,
`has_full_text` tinyint(1) NOT NULL DEFAULT '0',
`external_id` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`model_seed` varchar(128) COLLATE utf8_bin DEFAULT 'NONE',
`url` varchar(2083) COLLATE utf8_bin DEFAULT NULL,
`doi` varchar(1024) COLLATE utf8_bin DEFAULT NULL,
`issue` varchar(64) COLLATE utf8_bin DEFAULT NULL,
`issn` varchar(1024) COLLATE utf8_bin DEFAULT NULL,
`call_number` varchar(2083) COLLATE utf8_bin DEFAULT NULL,
`work_type` varchar(1024) COLLATE utf8_bin DEFAULT NULL,
`notes` varchar(10000) COLLATE utf8_bin DEFAULT NULL,
`custom_tags` blob,
PRIMARY KEY (`id`),
KEY `FK_reference_project` (`project`),
KEY `FK_reference_publication_source` (`publication_source`),
CONSTRAINT `FK_reference_project`
FOREIGN KEY (`project`)
REFERENCES `project` (`id`),
CONSTRAINT `FK_reference_publication_source`
FOREIGN KEY (`publication_source`)
REFERENCES `publicationsource` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10512575 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
Table B definition
CREATE TABLE publicationsource (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(128) COLLATE utf8_bin DEFAULT NULL,
type varchar(16) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (id),
KEY UK_publicationsource_type_name (type,name)
) ENGINE=InnoDB AUTO_INCREMENT=10921959 DEFAULT CHARSET=utf8 COLLATE=utf8_bin