我遇到以下问题:
当我执行以下语句时,我收到错误,因为它返回多行
INSERT INTO artist
(personid,
musicgenreid,
totallikes)
VALUES ( (SELECT personid
FROM person
WHERE firstname = 'Joe'
AND middlename = ''
AND lastname = 'blow'),
(SELECT musicgenreid
FROM musicgenre
WHERE musicgenreid = 4),
( totallikes = 328374 ) );
我在(从人...选择pesonID)语句中得到错误,我正在尝试使用'any'关键字来抓取任何行,但我似乎无法让它工作。我已经尝试过任何我能想到的当前查询和'any'的排列,但它不起作用。是否有其他解决方案我应该尝试,或者我因某种原因错过了标记?
答案 0 :(得分:1)
看来你正试图做这样的事情:
INSERT INTO artist (personid, musicgenreid, totallikes)
VALUES (
(SELECT personid FROM person
WHERE firstname = 'Joe' AND middlename = '' AND lastname = 'blow'
ORDER BY RAND()
LIMIT 1
),
4,
328374
);
这将为您提供符合给定条件的随机personid
。
您的查询中的musicgenreid
可能是null
或4
。我强迫它4
,因为您似乎手动添加了它们,并且您知道它们已经存在。
总喜欢字段也已修复,但您的语法不正确。
答案 1 :(得分:-1)
尝试使用此sql语句
INSERT INTO artist
(personid,
musicgenreid,
totallikes)
VALUES ( (SELECT personid
FROM person
WHERE firstname = 'Joe'
AND middlename = ''
AND lastname = 'blow' LIMIT 1 ),
4,
328374);