Try this:
UPDATE citations SET
citations.refPaperID = (SELECT papers.paperid
FROM papers
WHERE citations.title = papers.title
AND citations.year = papers.year)
But for this to work, the SELECT
query must match and return one single record, which means that the records in your citations table must have unique title+year combination.
Edit
MySQL does not have an implementation of FIRST()
and LAST()
, so to get the first match, you can use LIMIT 1
like this:
UPDATE citations SET
citations.refPaperID = (SELECT papers.paperid
FROM papers
WHERE citations.title = papers.title
AND citations.year = papers.year
LIMIT 1)