Mysql 展平子选择中位置的行

Mysql 展平子选择中位置的行,mysql,subquery,where-clause,Mysql,Subquery,Where Clause,我有一个客户表,其中有3列用于不同帐户的ID,如下所示: customers: id, account1_id, account2_id, account3_id SELECT * FROM balances WHERE account_id IN ( SELECT account1_id, account2_id, account3_id FROM customers ) 现在,我需要从所有这些列中选择ID,以便在另一个查询的WHERE部分中使用,如下所示: customers:

我有一个客户表,其中有3列用于不同帐户的ID,如下所示:

customers: id, account1_id, account2_id, account3_id
SELECT * FROM balances
WHERE account_id IN (
    SELECT account1_id, account2_id, account3_id FROM customers
)
现在,我需要从所有这些列中选择ID,以便在另一个查询的WHERE部分中使用,如下所示:

customers: id, account1_id, account2_id, account3_id
SELECT * FROM balances
WHERE account_id IN (
    SELECT account1_id, account2_id, account3_id FROM customers
)
当然它不起作用,因为它返回类似于二维数组的东西,我需要一维数组。 我尝试使用:

WHERE (`account_id`, `account_id`, `account_id`) IN (
    SELECT account1_id, account2_id, account3_id FROM customers
)
但这是我的身份证,我需要手术室。还尝试:

SELECT CONCAT_WS(',' account1_id, account2_id, account3_id) AS accounts FROM customers
但它也不起作用,因为我必须在返回的字符串中搜索

我尝试使用REGEXP,但无法使用subselect获得正确的语法,而且我不相信它会有效

那么,如何将二维阵列展平为一维阵列

SELECT balances.* 
FROM balances
JOIN customers ON balances.account_id IN ( customers.account1_id, 
                                           customers.account2_id, 
                                           customers.account3_id )

或者与WHERE EXISTS相同。

一个客户表,其中有3列用于不同帐户的ID,这样可以使其正常化。例如,to
(id,account\u id,account\u number)
.omg,我多么想!但它是遗留数据库,当然是不可触及的:(