how can i access column from subqueryInner join versus doing a where in clauseHow can I prevent SQL injection in PHP?Add a column with a default value to an existing table in SQL ServerSQL to find the number of distinct values in a columnPostgreSQL AutoincrementHow do I UPDATE from a SELECT in SQL Server?How can I drop all the tables in a PostgreSQL database?How to do an update + join in PostgreSQL?How to exit from PostgreSQL command line utility: psqlpsql: FATAL: database “<user>” does not existHow to import an SQL file using the command line in MySQL?

Increase performance creating Mandelbrot set in python

Why not increase contact surface when reentering the atmosphere?

How does Loki do this?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Do sorcerers' subtle spells require a skill check to be unseen?

What does "I’d sit this one out, Cap," imply or mean in the context?

Trouble understanding the speech of overseas colleagues

when is out of tune ok?

Is the destination of a commercial flight important for the pilot?

You cannot touch me, but I can touch you, who am I?

Anatomically Correct Strange Women In Ponds Distributing Swords

Sort a list by elements of another list

Purchasing a ticket for someone else in another country?

How easy is it to start Magic from scratch?

Is exact Kanji stroke length important?

Fastening aluminum fascia to wooden subfascia

Term for the "extreme-extension" version of a straw man fallacy?

Type int? vs type int

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Why Were Madagascar and New Zealand Discovered So Late?

How to safely derail a train during transit?

How does buying out courses with grant money work?

Is HostGator storing my password in plaintext?

Detecting if an element is found inside a container



how can i access column from subquery


Inner join versus doing a where in clauseHow can I prevent SQL injection in PHP?Add a column with a default value to an existing table in SQL ServerSQL to find the number of distinct values in a columnPostgreSQL AutoincrementHow do I UPDATE from a SELECT in SQL Server?How can I drop all the tables in a PostgreSQL database?How to do an update + join in PostgreSQL?How to exit from PostgreSQL command line utility: psqlpsql: FATAL: database “<user>” does not existHow to import an SQL file using the command line in MySQL?













0















 select u.phone, u.email , t.to_address (error from this)
from user_accounts u
where u.id
in
(select w.user_id
from wallets w
where w.id
in
(
select t.wallet_id
from withdraws t
where t.to_address
in
('1F6o1fZZ7', 'pJDtRRnyhDN')))


I want to get the column to_address from subquery. How can I get it in postgresql?



I try assign 'AS' for subquery but it didn't work










share|improve this question




























    0















     select u.phone, u.email , t.to_address (error from this)
    from user_accounts u
    where u.id
    in
    (select w.user_id
    from wallets w
    where w.id
    in
    (
    select t.wallet_id
    from withdraws t
    where t.to_address
    in
    ('1F6o1fZZ7', 'pJDtRRnyhDN')))


    I want to get the column to_address from subquery. How can I get it in postgresql?



    I try assign 'AS' for subquery but it didn't work










    share|improve this question


























      0












      0








      0








       select u.phone, u.email , t.to_address (error from this)
      from user_accounts u
      where u.id
      in
      (select w.user_id
      from wallets w
      where w.id
      in
      (
      select t.wallet_id
      from withdraws t
      where t.to_address
      in
      ('1F6o1fZZ7', 'pJDtRRnyhDN')))


      I want to get the column to_address from subquery. How can I get it in postgresql?



      I try assign 'AS' for subquery but it didn't work










      share|improve this question
















       select u.phone, u.email , t.to_address (error from this)
      from user_accounts u
      where u.id
      in
      (select w.user_id
      from wallets w
      where w.id
      in
      (
      select t.wallet_id
      from withdraws t
      where t.to_address
      in
      ('1F6o1fZZ7', 'pJDtRRnyhDN')))


      I want to get the column to_address from subquery. How can I get it in postgresql?



      I try assign 'AS' for subquery but it didn't work







      sql postgresql join






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 11:44









      a_horse_with_no_name

      305k46468564




      305k46468564










      asked Mar 8 at 11:12









      Nguyễn Minh HưngNguyễn Minh Hưng

      113




      113






















          3 Answers
          3






          active

          oldest

          votes


















          1














          A join returns a result table constructed from data from multiple tables. You can also retrieve the same result table using a sub query. A sub query is simply a SELECT statement within another select statement.



          select u.phone, u.email , t.to_address (
          from user_accounts u
          INNER JOIN wallets w ON u.id= w.user_id
          INNER JOIN withdraws t ON t.wallet_id =w.id
          where t.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')





          share|improve this answer






























            0














            use join with all the table, you dont need any subquery



             select u.phone, u.email , ww.to_address 
            from user_accounts u left join wallets w on u.id=w.user_id
            left jon withdraws ww on w.id=ww.wallet_id
            where ww.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')


            You can not access t.address because that column inside in condition.
            I used left join but it seems it will be inner join type because you used filter in ('1F6o1fZZ7', 'pJDtRRnyhDN') though after applying where condition it also behave like inner join






            share|improve this answer
































              0














              You cannot achieve what you're trying using subquery. When you want records from different tables and they have a unique column in common that connects them then You should do it using a JOIN.



              Sometimes (Not all cases) IN can cause performance problems, so you should consider knowing more about different types of JOINS(https://www.w3schools.com/sql/sql_join.asp)



              Check the link for comparison:
              Inner join versus doing a where in clause



              About the Query:



              SELECT
              u.phone, u.email , t.to_address (error from this)
              FROM
              user_accounts u
              INNER JOIN wallets w ON u.id = w.id
              INNER JOIN withdraws t ON t.wallet_id = w.id
              WHERE
              t.to_address IN ('1F6o1fZZ7', 'pJDtRRnyhDN')





              share|improve this answer

























              • You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                – Gordon Linoff
                Mar 8 at 11:59











              • Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                – a_horse_with_no_name
                Mar 8 at 12:02










              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062018%2fhow-can-i-access-column-from-subquery%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              A join returns a result table constructed from data from multiple tables. You can also retrieve the same result table using a sub query. A sub query is simply a SELECT statement within another select statement.



              select u.phone, u.email , t.to_address (
              from user_accounts u
              INNER JOIN wallets w ON u.id= w.user_id
              INNER JOIN withdraws t ON t.wallet_id =w.id
              where t.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')





              share|improve this answer



























                1














                A join returns a result table constructed from data from multiple tables. You can also retrieve the same result table using a sub query. A sub query is simply a SELECT statement within another select statement.



                select u.phone, u.email , t.to_address (
                from user_accounts u
                INNER JOIN wallets w ON u.id= w.user_id
                INNER JOIN withdraws t ON t.wallet_id =w.id
                where t.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')





                share|improve this answer

























                  1












                  1








                  1







                  A join returns a result table constructed from data from multiple tables. You can also retrieve the same result table using a sub query. A sub query is simply a SELECT statement within another select statement.



                  select u.phone, u.email , t.to_address (
                  from user_accounts u
                  INNER JOIN wallets w ON u.id= w.user_id
                  INNER JOIN withdraws t ON t.wallet_id =w.id
                  where t.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')





                  share|improve this answer













                  A join returns a result table constructed from data from multiple tables. You can also retrieve the same result table using a sub query. A sub query is simply a SELECT statement within another select statement.



                  select u.phone, u.email , t.to_address (
                  from user_accounts u
                  INNER JOIN wallets w ON u.id= w.user_id
                  INNER JOIN withdraws t ON t.wallet_id =w.id
                  where t.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 11:22









                  vishalvishal

                  17611




                  17611























                      0














                      use join with all the table, you dont need any subquery



                       select u.phone, u.email , ww.to_address 
                      from user_accounts u left join wallets w on u.id=w.user_id
                      left jon withdraws ww on w.id=ww.wallet_id
                      where ww.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')


                      You can not access t.address because that column inside in condition.
                      I used left join but it seems it will be inner join type because you used filter in ('1F6o1fZZ7', 'pJDtRRnyhDN') though after applying where condition it also behave like inner join






                      share|improve this answer





























                        0














                        use join with all the table, you dont need any subquery



                         select u.phone, u.email , ww.to_address 
                        from user_accounts u left join wallets w on u.id=w.user_id
                        left jon withdraws ww on w.id=ww.wallet_id
                        where ww.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')


                        You can not access t.address because that column inside in condition.
                        I used left join but it seems it will be inner join type because you used filter in ('1F6o1fZZ7', 'pJDtRRnyhDN') though after applying where condition it also behave like inner join






                        share|improve this answer



























                          0












                          0








                          0







                          use join with all the table, you dont need any subquery



                           select u.phone, u.email , ww.to_address 
                          from user_accounts u left join wallets w on u.id=w.user_id
                          left jon withdraws ww on w.id=ww.wallet_id
                          where ww.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')


                          You can not access t.address because that column inside in condition.
                          I used left join but it seems it will be inner join type because you used filter in ('1F6o1fZZ7', 'pJDtRRnyhDN') though after applying where condition it also behave like inner join






                          share|improve this answer















                          use join with all the table, you dont need any subquery



                           select u.phone, u.email , ww.to_address 
                          from user_accounts u left join wallets w on u.id=w.user_id
                          left jon withdraws ww on w.id=ww.wallet_id
                          where ww.to_address in ('1F6o1fZZ7', 'pJDtRRnyhDN')


                          You can not access t.address because that column inside in condition.
                          I used left join but it seems it will be inner join type because you used filter in ('1F6o1fZZ7', 'pJDtRRnyhDN') though after applying where condition it also behave like inner join







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 8 at 11:26

























                          answered Mar 8 at 11:16









                          Zaynul Abadin TuhinZaynul Abadin Tuhin

                          18.2k21134




                          18.2k21134





















                              0














                              You cannot achieve what you're trying using subquery. When you want records from different tables and they have a unique column in common that connects them then You should do it using a JOIN.



                              Sometimes (Not all cases) IN can cause performance problems, so you should consider knowing more about different types of JOINS(https://www.w3schools.com/sql/sql_join.asp)



                              Check the link for comparison:
                              Inner join versus doing a where in clause



                              About the Query:



                              SELECT
                              u.phone, u.email , t.to_address (error from this)
                              FROM
                              user_accounts u
                              INNER JOIN wallets w ON u.id = w.id
                              INNER JOIN withdraws t ON t.wallet_id = w.id
                              WHERE
                              t.to_address IN ('1F6o1fZZ7', 'pJDtRRnyhDN')





                              share|improve this answer

























                              • You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                                – Gordon Linoff
                                Mar 8 at 11:59











                              • Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                                – a_horse_with_no_name
                                Mar 8 at 12:02















                              0














                              You cannot achieve what you're trying using subquery. When you want records from different tables and they have a unique column in common that connects them then You should do it using a JOIN.



                              Sometimes (Not all cases) IN can cause performance problems, so you should consider knowing more about different types of JOINS(https://www.w3schools.com/sql/sql_join.asp)



                              Check the link for comparison:
                              Inner join versus doing a where in clause



                              About the Query:



                              SELECT
                              u.phone, u.email , t.to_address (error from this)
                              FROM
                              user_accounts u
                              INNER JOIN wallets w ON u.id = w.id
                              INNER JOIN withdraws t ON t.wallet_id = w.id
                              WHERE
                              t.to_address IN ('1F6o1fZZ7', 'pJDtRRnyhDN')





                              share|improve this answer

























                              • You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                                – Gordon Linoff
                                Mar 8 at 11:59











                              • Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                                – a_horse_with_no_name
                                Mar 8 at 12:02













                              0












                              0








                              0







                              You cannot achieve what you're trying using subquery. When you want records from different tables and they have a unique column in common that connects them then You should do it using a JOIN.



                              Sometimes (Not all cases) IN can cause performance problems, so you should consider knowing more about different types of JOINS(https://www.w3schools.com/sql/sql_join.asp)



                              Check the link for comparison:
                              Inner join versus doing a where in clause



                              About the Query:



                              SELECT
                              u.phone, u.email , t.to_address (error from this)
                              FROM
                              user_accounts u
                              INNER JOIN wallets w ON u.id = w.id
                              INNER JOIN withdraws t ON t.wallet_id = w.id
                              WHERE
                              t.to_address IN ('1F6o1fZZ7', 'pJDtRRnyhDN')





                              share|improve this answer















                              You cannot achieve what you're trying using subquery. When you want records from different tables and they have a unique column in common that connects them then You should do it using a JOIN.



                              Sometimes (Not all cases) IN can cause performance problems, so you should consider knowing more about different types of JOINS(https://www.w3schools.com/sql/sql_join.asp)



                              Check the link for comparison:
                              Inner join versus doing a where in clause



                              About the Query:



                              SELECT
                              u.phone, u.email , t.to_address (error from this)
                              FROM
                              user_accounts u
                              INNER JOIN wallets w ON u.id = w.id
                              INNER JOIN withdraws t ON t.wallet_id = w.id
                              WHERE
                              t.to_address IN ('1F6o1fZZ7', 'pJDtRRnyhDN')






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Mar 8 at 12:02

























                              answered Mar 8 at 11:56









                              Safi UllahSafi Ullah

                              236210




                              236210












                              • You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                                – Gordon Linoff
                                Mar 8 at 11:59











                              • Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                                – a_horse_with_no_name
                                Mar 8 at 12:02

















                              • You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                                – Gordon Linoff
                                Mar 8 at 11:59











                              • Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                                – a_horse_with_no_name
                                Mar 8 at 12:02
















                              You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                              – Gordon Linoff
                              Mar 8 at 11:59





                              You have a reference to a SQL Server performance question, but this question is tagged Postgres.

                              – Gordon Linoff
                              Mar 8 at 11:59













                              Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                              – a_horse_with_no_name
                              Mar 8 at 12:02





                              Additionally: not every IN condition can be rewritten as a JOIN. Those are two different things

                              – a_horse_with_no_name
                              Mar 8 at 12:02

















                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062018%2fhow-can-i-access-column-from-subquery%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                              List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229