Unable to select data from another joined table

Hatik

I have some tables with huge data, so I try to use that data to create a kind of a report, based on some conditions using `LEFT JOIN',

SELECT SUBSIDIARY, MAIN_ACCOUNT, AMOUNT ... FROM (
...
LEFT JOIN (SELECT MAIN_ACCOUNT, ACCOUNT_NO AS SUBSIDIARY FROM TABLE1 WHERE STATUS = 'A') K
ON MAIN_ACCOUNT = K.MAIN_ACCOUNT
LEFT JOIN (SELECT SUM(AMOUNT) AS AMOUNT, ACCOUNT_NO, FROM TABLE2 WHERE ACCOUNT_NO = K.ACCOUNT_NO GROUP_BY ACCOUNT_NO) L
ON SUBSIDIARY = L.ACCOUNT_NO --this is where i got into a problem
...
);

The problem is that I cannot access the K.ACCOUNT_NO from another join I have tried using WHERE ACCOUNT_NO = SUBSIDIARY since I select in the main SELECT. Does it mean that I cannot access previously queried data from another join?

Error I get:

ORA-00904: "SUBSIDIARY": invalid identifier

if I use k.subsidiary or k.account_no

ORA-00904: "k.SUBSIDIARY": invalid identifier
ORA-00904: "k.account_no": invalid identifier
Tien Nguyen Ngoc

You can not access the K.ACCOUNT_NO but you can INNER JOIN with TABLE1.

WHERE ACCOUNT_NO = K.ACCOUNT_NO

is replaced

INNER JOIN TABLE1 ON TABLE2.ACCOUNT_NO = TABLE1.ACCOUNT_NO AND TABLE1.STATUS = 'A' 

I hope it is helpful.

SELECT SUBSIDIARY, MAIN_ACCOUNT, AMOUNT ... FROM (
    ...
    LEFT JOIN (SELECT MAIN_ACCOUNT, ACCOUNT_NO AS SUBSIDIARY FROM TABLE1 WHERE STATUS = 'A') K
    ON MAIN_ACCOUNT = K.MAIN_ACCOUNT
    --this is where i got into a problem
    LEFT JOIN (SELECT SUM(AMOUNT) AS AMOUNT, ACCOUNT_NO, FROM TABLE2 INNER JOIN TABLE1 ON TABLE2.ACCOUNT_NO = TABLE1.ACCOUNT_NO AND TABLE1.STATUS = 'A' GROUP BY ACCOUNT_NO) L
    ON SUBSIDIARY = L.ACCOUNT_NO
    ...
    );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL select row with two matching joined rows from another table

From Dev

accessing data from a joined table

From Dev

Select from joined table only if record exists

From Dev

select record from joined table if it exists

From Dev

Select latest from joined table excluding duplicates

From Dev

Select only duplicates from inner joined table

From Dev

How to SELECT from a table if no data exists in another

From Dev

SELECT latest data from 2 joined tables

From Dev

Using column data from another table for the where clause of two joined tables

From Dev

select rows from table based on data from another table

From Dev

select rows from table based on data from another table

From Dev

Form with dropdown select that collects data from 2 joined mysql tables and save them into 1 table

From Dev

Get data from joined table in CakePHP

From Dev

view data from joined table in database

From Dev

How to select data from a table and insert into another table?

From Dev

How to select data from a table and insert into another table?

From Dev

How to select data from a table by referring to another table in MySQL

From Dev

Select data from one table with the conditions from another

From Dev

join table with another joined table

From Dev

Unable to display data from select input on the plot and in the table (at the same time)

From Dev

How to JOIN to a Function that requires a parameter from another joined table?

From Dev

Accessing joined table data

From Java

SQL How to select from multiple values in joined table

From Dev

Select columns from 2 joined table doctrine/symfony2

From Dev

How to select a minimal value from a joined table with JPA?

From Java

Using data.table to select rows by distance from another row

From Dev

MySQL Insert INTO using SELECT from another table with additional data

From Dev

Data Table - Select Value of Column by Name From Another Column

From Dev

MySQL: How to select data from a column in another table

Related Related

  1. 1

    MySQL select row with two matching joined rows from another table

  2. 2

    accessing data from a joined table

  3. 3

    Select from joined table only if record exists

  4. 4

    select record from joined table if it exists

  5. 5

    Select latest from joined table excluding duplicates

  6. 6

    Select only duplicates from inner joined table

  7. 7

    How to SELECT from a table if no data exists in another

  8. 8

    SELECT latest data from 2 joined tables

  9. 9

    Using column data from another table for the where clause of two joined tables

  10. 10

    select rows from table based on data from another table

  11. 11

    select rows from table based on data from another table

  12. 12

    Form with dropdown select that collects data from 2 joined mysql tables and save them into 1 table

  13. 13

    Get data from joined table in CakePHP

  14. 14

    view data from joined table in database

  15. 15

    How to select data from a table and insert into another table?

  16. 16

    How to select data from a table and insert into another table?

  17. 17

    How to select data from a table by referring to another table in MySQL

  18. 18

    Select data from one table with the conditions from another

  19. 19

    join table with another joined table

  20. 20

    Unable to display data from select input on the plot and in the table (at the same time)

  21. 21

    How to JOIN to a Function that requires a parameter from another joined table?

  22. 22

    Accessing joined table data

  23. 23

    SQL How to select from multiple values in joined table

  24. 24

    Select columns from 2 joined table doctrine/symfony2

  25. 25

    How to select a minimal value from a joined table with JPA?

  26. 26

    Using data.table to select rows by distance from another row

  27. 27

    MySQL Insert INTO using SELECT from another table with additional data

  28. 28

    Data Table - Select Value of Column by Name From Another Column

  29. 29

    MySQL: How to select data from a column in another table

HotTag

Archive