我有一個MySQL表像這樣MySQL查詢建議與訪問ID
ownerlisting_access_id property_id mainaccess_id subaccess_id access_value
62 2 35 41 Yes
64 2 35 36 Yes
123 4 35 41 Yes
125 4 35 36 Yes
306 7 35 41 Yes
307 7 35 42 Yes
308 7 35 36 Yes
我想要一個查詢,將使用subaccess_id(41,42,36)和mainaccess_id(35)給我這個輸出 -
ownerlisting_access_id property_id mainaccess_id subaccess_id access_value
306 7 35 41 Yes
307 7 35 42 Yes
308 7 35 36 Yes
我需要使用子訪問ID與41,42,以獲得作爲PROPERTY_ID 7,36
您在編寫的查詢中遇到了什麼問題?請向我們展示您的查詢。 –
SELECT * FROM'rt_ownerlisting_access' WHERE'mainaccess_id' = 35 AND('subaccess_id' = 41 OR'subaccess_id' = 42 OR'subaccess_id' = 36) 我得到所有記錄 SELECT * FROM'rt_ownerlisting_access' WHERE' mainaccess_id' = 35 AND('subaccess_id' = 41 AND'subaccess_id' = 42 AND'subaccess_id' = 36) 我沒有記錄 – mikejohnvino
它應該返回所有記錄,因爲所有記錄都有subaccess_id = 41,42或36 。 –