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: 
It is because after you set validInput to false in the first run of the loop with an invalid input, there is no code to set it to true in other attempts, hece going into an infinite loop, i.e. the while condition always fails.

What you need to do is set valdInput to true when the answer is within the valid expected values. For instance, modifying your original code:

```
bool validInput = true;
    do
{
            cout << "Choose your attacking animal:" << endl;
    cout << "1 = Bunny, 2 = Chicken, 3 = Kitty, 4 = Puppy, 5 = Wolverine" <<          endl;
    cin >> attacker;

    if (attacker < 1 || attacker > 5 || cin.fail())
    {
        cout << "Number must be 1 through 5" << endl;

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

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

```

Let me know if this helps.
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');

```