Select entries by list of ids from subquery?Insert into … values ( SELECT … FROM … )How do I perform an IF…THEN in an SQL SELECT?How do I UPDATE from a SELECT in SQL Server?Select first row in each GROUP BY group?How to exit from PostgreSQL command line utility: psqlSubtracting 1 day from a timestamp dateSelect all rows where array contains values from a given list in PostgresConverting Oracle date arithmetic to PostgreSQLfunction does not exists in postgreSQL .. Why ?PostgresSQL 10.6 - function substring & regexp_matches function does not exist

Is multiplication of real numbers uniquely defined as being distributive over addition?

Looking for a new job because of relocation - is it okay to tell the real reason?

What is the best way to cause swarm intelligence to be destroyed?

What are good ways to improve as a writer other than writing courses?

Does this smartphone photo show Mars just below the Sun?

Does two puncture wounds mean venomous snake?

How can I tell if a flight itinerary is fake?

How would I as a DM create a smart phone-like spell/device my players could use?

Working examples for SemidefiniteOptimization

Does a code snippet compile? Or does it gets compiled?

Does this Foo machine halt?

What is a "Genuine Geraldo interviewee"?

What word can be used to describe a bug in a movie?

Plausibility of Ice Eaters in the Arctic

Generator for parity?

sed delete all the words before a match

In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?

Can an SPI slave start a transmission in full-duplex mode?

Is refreshing multiple times a test case for web applications?

Yajilin minicubes: the Hullabaloo, the Brouhaha, the Bangarang

Blocking people from taking pictures of me with smartphone

Where to pee in London?

Why couldn't soldiers sight their own weapons without officers' orders?

How many numbers in the matrix?



Select entries by list of ids from subquery?


Insert into … values ( SELECT … FROM … )How do I perform an IF…THEN in an SQL SELECT?How do I UPDATE from a SELECT in SQL Server?Select first row in each GROUP BY group?How to exit from PostgreSQL command line utility: psqlSubtracting 1 day from a timestamp dateSelect all rows where array contains values from a given list in PostgresConverting Oracle date arithmetic to PostgreSQLfunction does not exists in postgreSQL .. Why ?PostgresSQL 10.6 - function substring & regexp_matches function does not exist






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In PostgreSQL database I make such SQL request:



SQL:



SELECT 
ARRAY_AGG (QUESTION_ID) AS QUESTIONS
FROM
factors_questions_relationship
WHERE
FACTOR_ID IN (SELECT ARRAY_AGG (FACTOR_ID) AS FACTORS
FROM surveys_factors_relationship
WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38');


ERROR:




This SQL request raise error:

SQL Error [42883]: ERROR: operator does not exist: integer = integer[]

No operator matches the given name and argument types. You might need to add explicit type casts.




Second subquery return list of ids: 2,10,12,44,52. I want to use that list of ids in main query. How to make it correctly?










share|improve this question
































    1















    In PostgreSQL database I make such SQL request:



    SQL:



    SELECT 
    ARRAY_AGG (QUESTION_ID) AS QUESTIONS
    FROM
    factors_questions_relationship
    WHERE
    FACTOR_ID IN (SELECT ARRAY_AGG (FACTOR_ID) AS FACTORS
    FROM surveys_factors_relationship
    WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38');


    ERROR:




    This SQL request raise error:

    SQL Error [42883]: ERROR: operator does not exist: integer = integer[]

    No operator matches the given name and argument types. You might need to add explicit type casts.




    Second subquery return list of ids: 2,10,12,44,52. I want to use that list of ids in main query. How to make it correctly?










    share|improve this question




























      1












      1








      1








      In PostgreSQL database I make such SQL request:



      SQL:



      SELECT 
      ARRAY_AGG (QUESTION_ID) AS QUESTIONS
      FROM
      factors_questions_relationship
      WHERE
      FACTOR_ID IN (SELECT ARRAY_AGG (FACTOR_ID) AS FACTORS
      FROM surveys_factors_relationship
      WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38');


      ERROR:




      This SQL request raise error:

      SQL Error [42883]: ERROR: operator does not exist: integer = integer[]

      No operator matches the given name and argument types. You might need to add explicit type casts.




      Second subquery return list of ids: 2,10,12,44,52. I want to use that list of ids in main query. How to make it correctly?










      share|improve this question
















      In PostgreSQL database I make such SQL request:



      SQL:



      SELECT 
      ARRAY_AGG (QUESTION_ID) AS QUESTIONS
      FROM
      factors_questions_relationship
      WHERE
      FACTOR_ID IN (SELECT ARRAY_AGG (FACTOR_ID) AS FACTORS
      FROM surveys_factors_relationship
      WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38');


      ERROR:




      This SQL request raise error:

      SQL Error [42883]: ERROR: operator does not exist: integer = integer[]

      No operator matches the given name and argument types. You might need to add explicit type casts.




      Second subquery return list of ids: 2,10,12,44,52. I want to use that list of ids in main query. How to make it correctly?







      sql postgresql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 6:15









      marc_s

      600k135 gold badges1149 silver badges1285 bronze badges




      600k135 gold badges1149 silver badges1285 bronze badges










      asked Mar 27 at 5:50









      Nurzhan NogerbekNurzhan Nogerbek

      1,2292 gold badges22 silver badges51 bronze badges




      1,2292 gold badges22 silver badges51 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can try below -



          SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship 
          where FACTOR_ID IN
          (
          SELECT FACTOR_ID AS FACTORS FROM surveys_factors_relationship
          WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38'
          )





          share|improve this answer



























          • Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

            – Nurzhan Nogerbek
            Mar 27 at 5:55












          • @NurzhanNogerbek, edited it - check now

            – fa06
            Mar 27 at 5:56











          • I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

            – Nurzhan Nogerbek
            Mar 27 at 6:02











          • @NurzhanNogerbek, I've edited the answer - you can check now

            – fa06
            Mar 27 at 6:51










          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%2f55370591%2fselect-entries-by-list-of-ids-from-subquery%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can try below -



          SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship 
          where FACTOR_ID IN
          (
          SELECT FACTOR_ID AS FACTORS FROM surveys_factors_relationship
          WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38'
          )





          share|improve this answer



























          • Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

            – Nurzhan Nogerbek
            Mar 27 at 5:55












          • @NurzhanNogerbek, edited it - check now

            – fa06
            Mar 27 at 5:56











          • I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

            – Nurzhan Nogerbek
            Mar 27 at 6:02











          • @NurzhanNogerbek, I've edited the answer - you can check now

            – fa06
            Mar 27 at 6:51















          1














          You can try below -



          SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship 
          where FACTOR_ID IN
          (
          SELECT FACTOR_ID AS FACTORS FROM surveys_factors_relationship
          WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38'
          )





          share|improve this answer



























          • Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

            – Nurzhan Nogerbek
            Mar 27 at 5:55












          • @NurzhanNogerbek, edited it - check now

            – fa06
            Mar 27 at 5:56











          • I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

            – Nurzhan Nogerbek
            Mar 27 at 6:02











          • @NurzhanNogerbek, I've edited the answer - you can check now

            – fa06
            Mar 27 at 6:51













          1












          1








          1







          You can try below -



          SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship 
          where FACTOR_ID IN
          (
          SELECT FACTOR_ID AS FACTORS FROM surveys_factors_relationship
          WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38'
          )





          share|improve this answer















          You can try below -



          SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship 
          where FACTOR_ID IN
          (
          SELECT FACTOR_ID AS FACTORS FROM surveys_factors_relationship
          WHERE SURVEY_ID = '9bef1274-f1ee-4879-a60e-16e94e88df38'
          )






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 6:50

























          answered Mar 27 at 5:52









          fa06fa06

          24.1k4 gold badges11 silver badges20 bronze badges




          24.1k4 gold badges11 silver badges20 bronze badges















          • Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

            – Nurzhan Nogerbek
            Mar 27 at 5:55












          • @NurzhanNogerbek, edited it - check now

            – fa06
            Mar 27 at 5:56











          • I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

            – Nurzhan Nogerbek
            Mar 27 at 6:02











          • @NurzhanNogerbek, I've edited the answer - you can check now

            – fa06
            Mar 27 at 6:51

















          • Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

            – Nurzhan Nogerbek
            Mar 27 at 5:55












          • @NurzhanNogerbek, edited it - check now

            – fa06
            Mar 27 at 5:56











          • I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

            – Nurzhan Nogerbek
            Mar 27 at 6:02











          • @NurzhanNogerbek, I've edited the answer - you can check now

            – fa06
            Mar 27 at 6:51
















          Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

          – Nurzhan Nogerbek
          Mar 27 at 5:55






          Hello! I tested your code right now. Unfortunately it raise error: SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE. Do you have any other ideas?

          – Nurzhan Nogerbek
          Mar 27 at 5:55














          @NurzhanNogerbek, edited it - check now

          – fa06
          Mar 27 at 5:56





          @NurzhanNogerbek, edited it - check now

          – fa06
          Mar 27 at 5:56













          I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

          – Nurzhan Nogerbek
          Mar 27 at 6:02





          I don't know why but your code return empty result. In fact if I make such sql request SELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52) I have result like 7,8,9,10,11,12,39,40,41,42,43,47,48 which is correct. What do you think about that?

          – Nurzhan Nogerbek
          Mar 27 at 6:02













          @NurzhanNogerbek, I've edited the answer - you can check now

          – fa06
          Mar 27 at 6:51





          @NurzhanNogerbek, I've edited the answer - you can check now

          – fa06
          Mar 27 at 6:51








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55370591%2fselect-entries-by-list-of-ids-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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript