OK,這裏有雲,我有3個表:雙select語句的問題,多行返回,子查詢返回多個值
accounts (account_id, employee_id, account_name)
projects (project_id, project_name)
project_distribution (distribution_id, employee_id, project_id)
我想要做的是從項目返回項目名稱表,如果我有project_distribution表中的項目id。所以,讓我們假設我有employee_id,我要進入project_distribution並做一個select,我得到2個值爲project_id,id 1和2,我如何返回project_names對於這兩個ID沒有做2個querys或statemens或他們如何正確調用,這是我的糟糕的選擇語句。
SELECT project_name
FROM projects
WHERE project_id = (SELECT project_id
FROM project_distribution
WHERE employee_id = (SELECT employee_id
FROM accounts
WHERE account_name = 'tbogdan'
)
);
oufcorse我將得到project_distribution 2倍的值,而「子查詢返回多個值」的錯誤,我怎麼能解決這個問題,並使其發揮作用? 如果需要更多的信息,請諮詢......對不起,模糊的描述......
請花一些時間格式化所有內容,以便閱讀和消化。 –