jd_h2003
jd_h2003

Reputation: 304

how to query a list of values names in a column of PostgresSQL

I'm fairly new to SQL, and am having trouble with a relatively simple query, but for some odd reason I cannot get it to work.

I am trying to pull a dataset based on values within that dataset meeting certain criteria. In python, it's relatively simple, but I cannot import the dataset of 20 million rows, and only need about 20 thousand.

Logically, I'd think you can pass a list of values to SQL to filter based on columns, but it doesn't seem to work.

My code is below:

SELECT * FROM dataset
WHERE column_1 = ['value_in_column_1', 'another_value_in_column_1', 'third_value_in_column_1']
ORDER BY date DESC
LIMIT 250;

However, that returns syntax error messages.

My though process was that since I can query by saying WHERE column_1 = value_in_column_1, I should be able to add additional values to it, but it seems it's not the case.

Any help is appreciated.

Upvotes: 0

Views: 92

Answers (1)

Stu
Stu

Reputation: 32629

It looks like you just need to use in with a specific list of values, such as

SELECT * FROM dataset
WHERE column_1 in('value_in_column_1', 'another_value_in_column_1',...)

Upvotes: 1

Related Questions