I have a Sqlite database and I created a View accounts_in_transactions using Select and Union All statements as shown below:
CREATE VIEW accounts_in_transactions AS
SELECT transactions_data._id,
((transactions_data.value) * -1) AS value,
transactions_data.acc_from_id AS acc_id,
transactions_data.acc_name_from AS acc_name
FROM transactions_data
UNION ALL
SELECT transactions_data._id,
transactions_data.value AS value, transactions_data.type,
transactions_data.acc_to_id AS acc_id,
transactions_data.acc_name_to AS acc_name
FROM transactions_data;
I run SELECT * FROM accounts_in_transactions; and I get the results as expected.
But when I try to do this:
SELECT accounts_in_transactions.acc_id, accounts._id
FROM acounts JOIN accounts_in_transactions
ON accounts._id = accounts_in_transactions.acc_id;
I get no result. (and accounts._id have the same values in accounts_in_transactions.acc_id)
But if I use this:
SELECT transactions_data.acc_from_id, transactions_data.acc_to_id , accounts._id
FROM accounts JOIN transactions_data
ON accounts._id IN (transactions_data.acc_from_id, transactions_data.acc_to_id);
It works fine...
Is there a problem in my code, or I can't use Join in a query with a View resulted from UNION ALL statement, or is this a limitation in Sqlite?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire