這是我的子查詢,我無法理解錯誤:1242 - 子查詢回傳超過 1 行
SELECT DISTINCT u.id as userId,
(
SELECT a10.description
FROM Export exp
INNER JOIN Account a10 ON (a10.id = exp.accountId)
WHERE exp.isActive = 1
AND exp.platformId = 14
) as structur
FROM User u
LEFT JOIN AccountUser au ON au.userId = u.id and au.isDefault = 1
LEFT JOIN Account a ON a.id = au.accountId
WHERE u.id > 0
ORDER BY u.id ASC
LIMIT 10
錯誤:1242 - 子查詢回傳超過 1 行
SELECT DISTINCT u.id as userId,
(
SELECT a10.description
FROM Export exp
感謝您的幫助
uj5u.com熱心網友回復:
您的子查詢回傳不止一行,但一個行單元格只接受一個值,所以如果您真的需要這個子查詢,那么您應該限制結果
SELECT DISTINCT u.id as userId,
(
SELECT a10.description
FROM Export exp
INNER JOIN Account a10 ON (a10.id = exp.accountId)
WHERE exp.isActive = 1
AND exp.platformId = 14
LIMIT 1
) as structur
FROM User u
LEFT JOIN AccountUser au ON au.userId = u.id and au.isDefault = 1
LEFT JOIN Account a ON a.id = au.accountId
WHERE u.id > 0
ORDER BY u.id ASC
LIMIT 10
但是查看您的代碼,您還可以避免子查詢在主查詢中添加連接
SELECT DISTINCT u.id as userId, Account.description structur
FROM User u
LEFT JOIN AccountUser au ON au.userId = u.id and au.isDefault = 1
LEFT JOIN Account a ON a.id = au.accountId
LEFT JOIN exp ON ON Account.id = exp.accountId
AND exp.isActive = 1
AND exp.platformId = 14
WHERE u.id > 0
ORDER BY u.id ASC
LIMIT 10
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/377395.html
標籤:mysql
上一篇:如何在表中選擇N個隨機組
