Mysql
Mysql子查詢返回多於1行
SELECT * FROM wp_posts WHERE ID IN ( (SELECT courses FROM wp_category WHERE CatID =401) OR (SELECT meta_value FROM wp_postmeta WHERE post_id IN (SELECT courses FROM wp_category WHERE CatID =401) AND meta_key ='post_id' ) ) AND ID IN (SELECT post_id FROM wp_locations_courses WHERE location_id = 1120)
我在使用
IN
子查詢時遇到上述查詢的問題,這給了我錯誤Subquery returns more than 1 row
,為什麼在我使用IN
子句時會發生這種情況
(SELECT courses FROM wp_category WHERE CatID =401) OR (SELECT meta_value FROM wp_postmeta WHERE post_id IN (SELECT courses FROM wp_category WHERE CatID =401) AND meta_key ='post_id' )
這是一個條件,但你需要
n
價值觀。這應該有效:
( ID IN ( (SELECT courses FROM wp_category WHERE CatID =401) ) OR ID IN ( (SELECT meta_value FROM wp_postmeta WHERE post_id IN (SELECT courses FROM wp_category WHERE CatID =401) AND meta_key ='post_id' ) ) )
還要注意 MySQL 的子查詢。在您的情況下,子查詢。