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

                              Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                              Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                              How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page