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;
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
add a comment |
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
add a comment |
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
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
sql postgresql
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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'
)
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 requestSELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52)
I have result like7,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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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'
)
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 requestSELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52)
I have result like7,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
add a comment |
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'
)
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 requestSELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52)
I have result like7,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
add a comment |
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'
)
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'
)
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 requestSELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52)
I have result like7,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
add a comment |
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 requestSELECT ARRAY_AGG (QUESTION_ID) AS QUESTIONS FROM factors_questions_relationship WHERE FACTOR_ID IN (2,10,12,44,52)
I have result like7,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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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