3

I have below table with data

create table stud(key int, person text, subject_id int[]);

insert into stud select 1,'Alex',array[2,7,9];
insert into stud select 2,'Peter',array[4,9,12];
insert into stud select 3,'Tokaver',array[8];
insert into stud select 4,'Machel',array[11,15];

Table looks

enter image description here

I can filter single subject_id in where like

select * from stud where 9=any(subject_id)

How can we filter more than one subject_id in where clause like

select * from stud where (8,9) in any(subject_id)

1 Answer 1

4

demo:db<>fiddle

You can use the overlap operator && for arrays:

select * from stud 
where array[8,9] && subject_id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.