Question: I want to produce the following sql using active record.

```
WHERE (column_name1, column_name1) IN (SELECT ....)

```

I don't know how to do this is active record.

I've tried these so far

```
where('column_name1, column_name2' => {})
where([:column_name1, :column_name2] => {})

```

This is the full query I'd like to create

```
SELECT a, Count(1) 
            FROM   table 
            WHERE  ( a, b ) IN (SELECT a, 
                                    Max(b) 
                                    FROM   table 
                                    GROUP  BY a) 
            GROUP  BY a 
            HAVING Count(1) > 1)

```

I've already written a scope for the subquery

Thanks in advance.

Answer: 
As LarsEggert already stated you never set back back the valid-flag to true if the input was in fact valid.

I would solve it in the following way:

```
bool validInput;
do {
  // Assumption: Input will be valid (Loop will not repeat in this case)
  validInput = true;
  cout << "Choose your attacking animal:" << endl;
  cout << "1 = Bunny, 2 = Chicken, 3 = Kitty, 4 = Puppy, 5 = Wolverine" << endl;
  cin >> attacker;

  // Check if assumption was wrong (Loop will run again in this case)
  if (attacker < 1 || attacker > 5 || cin.fail())
  {
    cout << "Number must be 1 through 5" << endl;

    cin.clear();
    cin.ignore();
    validInput = false;
  }
} while (!validInput);

cout << "Choose how many " << attacker<< " are attacking"<<endl;
cin >> attNum;

```

In compare to Jorge Torres's answer you won't have to write the else-case.

I typically follow this form for loops:

```
bool repeat;
do {
  repeat = false

  // do something
  // if loop has to be repeated, just set repeat = true somewhere here
} while(repeat);

```

This way you don't have a negation in your while and you also just have to focus on the cases where the repeat-flag has to be set.
It's because if the input is wrong, it's not extracted and removed from the input buffer, and since you call [`std::istream::ignore`](http://en.cppreference.com/w/cpp/io/basic_istream/ignore) without argument you only extract a single character from the invalid input, and if there's more invalid input after that then your next input will read that.

You could use [`std::istream::ignore`](http://en.cppreference.com/w/cpp/io/basic_istream/ignore) to extract (and discard) input until the next newline like this:

```
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

```