3

INSERT INTO People(Track_id_Reference) 
SELECT track_id 
FROM Tracks 
WHERE track_title IN (SELECT tracktitle 
                      FROM top100 
                      WHERE artist IN (SELECT p.People_name, t.artist 
                                       FROM People AS p 
                                       RIGHT JOIN top100 AS t 
                                       ON 
                                       p.People_name=t.artist 
                                       UNION DISTINCT 
                                       SELECT p.People_name, t.artist 
                                       FROM People AS p 
                                       LEFT JOIN top100 AS t 
                                       ON 
                                       p.People_name=t.artist));

私が得るエラーは

ERROR 1241 (21000): Operand should contain 1 column(s)

ユニオンが2列を返すサブクエリ。どうすればこれを修正できますか?

4

1 に答える 1

8

FROMあなたは条項を欠いています

SELECT track_id 
FROM   tableName
WHERE track_title 

したがって、完全なクエリは

INSERT INTO People (Track_id_Reference)
SELECT track_id
FROM                                      -- <<== add tableName here
WHERE track_title = (
                SELECT tracktitle
                FROM top100
                WHERE artist = (
                                SELECT p.People_name,
                                        t.artist
                                FROM People AS p
                                RIGHT JOIN top100 AS t
                                        ON p.People_name = t.artist

                                UNION

                                        DISTINCT
                                SELECT p.People_name,
                                        t.artist
                                FROM People AS p
                                LEFT JOIN top100 AS t
                                        ON p.People_name = t.artist
                                )
                );

すぐに発生するもう1つの問題は、サブクエリの結果に等号を使用することです。たとえば、サブクエリが複数の値を返す場合に例外をスローするため、使用する方=がはるかに安全です。例、IN=

INSERT INTO People (Track_id_Reference)
SELECT track_id
FROM                                      -- <<== add tableName here
WHERE track_title IN (
                SELECT tracktitle
                FROM top100 .............
于 2012-11-25T06:38:13.633 に答える