我现有的查询如下所示:
SELECT
id,
refid,
action_id,
action_type,
co_user_id,
cust_vend_id,
Aes_decrypt(cust_vend_name, '".DBKEY."') AS cust_vend_name,
Aes_decrypt(amount, '".DBKEY."') AS amount,
Aes_decrypt(action_date, '".DBKEY."') AS action_date,
Aes_decrypt(memo, '".DBKEY."') AS memo,
Aes_decrypt(trans_id, '".DBKEY."') AS trans_id,
part_id,
polarity
FROM generated_actions
INNER join
generated_actions.action_id AS action_id
ON
(generated_actions.action
WHERE acc_type = 2
AND acc_id = $ba_id
AND reverse_id IS NULL
ORDER BY action_id,
Aes_decrypt(action_date, '".DBKEY."'),
entry_datetime ;
但是对于它选择的每条记录,我还需要它从一条记录中返回另一列,否则它会被排除在外(因为它的 acc_id 是“1”而不是“2”)。因此,我需要它来查找 acc_id AS 'account',其中 action_id 与其当前选择的记录相同,part_id = '3'。
该查询将选择多条记录,但它不会为附加条件的每条记录找到匹配项。在这种情况下,它仍应返回主记录,但将 null 作为 'accounts' 的值。
我的替代方法是使用我提供的查询,然后对于每个结果,再次检查同一个表 SELECT acc_id WHERE action_id = $action_id AND part_id = '3'。我认为必须有一种方法可以在一个查询中执行此操作?
我正在使用 MySQL。