I have the following:
time_range = (1.month.ago.beginning_of_month..1.month.ago.end_of_month) Comment.where(:created_at => time_range).count
How can I add to the where clause with a statement like:
.where("user_id is not in (?)",[user_ids]).
How can I combine the two? Thanks
Syntax. SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]... AND [conditionN]; You can combine N number of conditions using the AND operator.
But yes, you can use two WHERE.
The SQL JOIN is an important tool for combining information from several tables. Most often, you'll be joining tables based on a primary key from one table and a foreign key from another table. However, it is also often the case that you need to join tables by two or more columns.
if you want a "AND" conditional query, try this:
Comment. where(:created_at => time_range). where("user_id is not in (?)",[user_ids])
which will produce SQL like : select ... where ... AND ...
if you want the WHERE clause more complicated, such as: where ( a AND b) OR (c AND d)
, you have to combine the conditions into the clause yourself, e.g.
Comment.where("(a AND b ) OR (c AND d)")
User.where(["name = ? and email = ?", "Joe", "[email protected]"])
This will be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With