Jon
Jon

Reputation: 3985

Select everything in a database that == something OR something else

I'm trying to select everything in a table where a column == "something" OR "somethingelse".

Is there a way of doing this without using raw SQL? Something like the following would be ideal.

Table.where(:col => "something" OR "somethingelse")

Upvotes: 3

Views: 179

Answers (3)

Prateek
Prateek

Reputation: 241

You can use the statement like this:

select * from table_name where column_name = value1 or column_name = value_2

You can also use:

select * from table_name where column_name in (value1,value2)

Upvotes: -1

ryeguy
ryeguy

Reputation: 66851

Table.where(:col => ["something", "somethingelse"])

should generate

SELECT * FROM table WHERE col IN ('something', 'somethingelse')

Upvotes: 5

Joe
Joe

Reputation: 366

You can use:

MyModel.where("col1 = ? or col1 = ?", "something","somethingelse")

Upvotes: 2

Related Questions