-2

I have a table where each cell in columns has an array list.

          COL1              COL2 
row1: ('hi','hello')    ('hi','hello')
row2: ('hihi','below')    ('pi','by') 

I am trying to use an in operator on such data but my query is not returning anything.

Query: select * from table where col1 in ('hi')

Also, if I have another table (table2) that looks like this:

col3
____
'hi'
'bye'
'guy'

and I want to use the same concept where I'll be checking if 'hi','bye','guy' from col3 exists in col1 row1

My Query: select * from table2 where col3 in (select col1 from table1);
LalaLand
  • 139
  • 3
  • 14
  • 1
    There is no such thing as "an array within a cell" in databases. Each cell contains a single piece of data. – Alejandro Aug 11 '21 at 14:35
  • 1
    If you are using a database that has a concept of arrays, it's non-standard. So please do as the [tag:sql] tag already asked you to do and add a tag identifying which database product you're actually working with. – Damien_The_Unbeliever Aug 11 '21 at 14:40
  • `in` works on a *relational set of rows* - it does not parse strings. You should tag the RDBMS you are using. – Stu Aug 11 '21 at 15:46
  • If this is postgresql have a look at [array functions and operators](https://www.postgresql.org/docs/current/functions-array.html). – Steeeve Aug 11 '21 at 19:26

1 Answers1

0

The first argument is the "inside" one, the second one is the group of values.

You are comparing col1 (a tuple of 2 values) to a unique value:

I think that could help you: col1[0] -> gets the first value

select * from table where col1[0] in ('hi')

Whether you want to compare both, you can use:

select * from table where col1[0] in ('hi') or col1[1] in ('hi')